473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

weird problem with gcc

I hope I'm not annoying anyone here with this kind of newbie question,
anyway here it is:
What is wrong with this code here?

const int ARRAY_SIZE = 10;

gcc says: error: two or more data types in declaration of 'ARRAY_SIZE'

I've checked a few other sites and that confirmed that there isn't
really anything wrong with it at first glance.
This happened on a Mac with OS X 10.4.3 and this version of gcc:
powerpc-apple-darwin8-gcc-4.0.0
and also on a i586 running SuSE 10.

Thanks in advance for your help

Dec 16 '05 #1
22 1265
mini_t wrote:
I hope I'm not annoying anyone here with this kind of newbie question,
anyway here it is:
What is wrong with this code here?

const int ARRAY_SIZE = 10;

gcc says: error: two or more data types in declaration of 'ARRAY_SIZE'

I've checked a few other sites and that confirmed that there isn't
really anything wrong with it at first glance.
This happened on a Mac with OS X 10.4.3 and this version of gcc:
powerpc-apple-darwin8-gcc-4.0.0
and also on a i586 running SuSE 10.

Thanks in advance for your help


There's nothing wrong with it on the surface. Post a minimal *but
complete* code sample that demonstrates the problem.

Cheers! --M

Dec 16 '05 #2

mini_t wrote:
I hope I'm not annoying anyone here with this kind of newbie question,
anyway here it is:
What is wrong with this code here?

const int ARRAY_SIZE = 10;

gcc says: error: two or more data types in declaration of 'ARRAY_SIZE'

I've checked a few other sites and that confirmed that there isn't
really anything wrong with it at first glance.
This happened on a Mac with OS X 10.4.3 and this version of gcc:
powerpc-apple-darwin8-gcc-4.0.0
and also on a i586 running SuSE 10.


it looks ok to me. So if wierd things seem to be happening then suspect
the
preprocessor. Try

const int array_size = 10;

in general don't use all-uppercase for anything except macros
--
Nick Keighley

Dec 16 '05 #3
mini_t wrote:
I hope I'm not annoying anyone here with this kind of newbie question,
anyway here it is:
What is wrong with this code here?

const int ARRAY_SIZE = 10;

gcc says: error: two or more data types in declaration of 'ARRAY_SIZE'
Look at the previous line, maybe you're missing a semicolon there.
I've checked a few other sites and that confirmed that there isn't
really anything wrong with it at first glance.
This happened on a Mac with OS X 10.4.3 and this version of gcc:
powerpc-apple-darwin8-gcc-4.0.0
and also on a i586 running SuSE 10.


Next time begin with reading the FAQ. Your assignment today is 5.8.

V
Dec 16 '05 #4
mini_t <se*************@gmail.com> wrote:
I hope I'm not annoying anyone here with this kind of newbie question,
anyway here it is:
What is wrong with this code here?

const int ARRAY_SIZE = 10;

gcc says: error: two or more data types in declaration of 'ARRAY_SIZE'

I've checked a few other sites and that confirmed that there isn't
really anything wrong with it at first glance.
This happened on a Mac with OS X 10.4.3 and this version of gcc:
powerpc-apple-darwin8-gcc-4.0.0
and also on a i586 running SuSE 10.

Thanks in advance for your help


My first inclination is that ARRAY_SIZE is some macro that is #define'd
somewhere.

--
Marcus Kwok
Dec 16 '05 #5
Marcus Kwok wrote:
mini_t <se*************@gmail.com> wrote:
I hope I'm not annoying anyone here with this kind of newbie question,
anyway here it is:
What is wrong with this code here?

const int ARRAY_SIZE = 10;

gcc says: error: two or more data types in declaration of 'ARRAY_SIZE'

I've checked a few other sites and that confirmed that there isn't
really anything wrong with it at first glance.
This happened on a Mac with OS X 10.4.3 and this version of gcc:
powerpc-apple-darwin8-gcc-4.0.0
and also on a i586 running SuSE 10.

Thanks in advance for your help

My first inclination is that ARRAY_SIZE is some macro that is #define'd
somewhere.


If it were true, the error wouldn't have 'ARRAY_SIZE' spelled out, it
would have the substituted text there, I think.

V
Dec 16 '05 #6
ok, here's the way the code is in the program (it's actually part of a
c++ course i'm doing):

#include <iostream>
#include <iomanip>
using namespace std;
#include "Salaried.h"
const int array_size = 10; // maximum number of employees
// function prototypes
int createEmployee( SalariedEmployee * [], int );
void displayEmployees( SalariedEmployee * [], int );
int main()
{
int count = 0;
int selection = 0;
cout << fixed << setprecision( 2 );
SalariedEmployee *employees[ array_size ];

Dec 16 '05 #7
mini_t wrote:
ok, here's the way the code is in the program (it's actually part of a
c++ course i'm doing):

#include <iostream>
#include <iomanip>
using namespace std;
#include "Salaried.h"
const int array_size = 10; // maximum number of employees
// function prototypes
int createEmployee( SalariedEmployee * [], int );
void displayEmployees( SalariedEmployee * [], int );
int main()
{
int count = 0;
int selection = 0;
cout << fixed << setprecision( 2 );
SalariedEmployee *employees[ array_size ];


We'll need to see the content of Salaried.h, too. That's likely where
the problem is.

BTW, you should prefer std::vector to standard arrays. See this FAQ:

http://www.parashift.com/c++-faq-lit....html#faq-34.1

Cheers! --M

Dec 16 '05 #8
thanks for the advice about arrays, here's Salaried.h
#ifndef SALARIED_H
#define SALARIED_H

#include "Employee.h" // Employee class definition

class SalariedEmployee : public Employee {

public:
SalariedEmployee( string &, string &, string &, double
= 0.0 );

void setWeeklySalary( double );
double getWeeklySalary();

void print(); // displays "Salaried employee: "

private:
double weeklySalary;

} // end class SalariedEmployee
#endif // SALARIED_H
and Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include <string> // required to access string functions

using namespace std; // for accessing C++ Standard Library members

class Employee {

public:
Employee( string &, string &, string & );

void setFirstName( string & );
string getFirstName();

void setLastName( string & );
string getLastName();

void setSocialSecurityNumber( string & );
string getSocialSecurityNumber();

// member function to be overridden
void print(); // display employee information

private:
string firstName;
string lastName;
string socialSecurityNumber;

}; // end class Employee

#endif // EMPLOYEE_H

Dec 16 '05 #9
mini_t wrote:
ok, here's the way the code is in the program (it's actually part of a
c++ course i'm doing):

#include <iostream>
#include <iomanip>
using namespace std;
#include "Salaried.h"
What's inside this one? Does it have a class definition that ends on
a curly brace without the closing semicolon?
const int array_size = 10; // maximum number of employees
// function prototypes
int createEmployee( SalariedEmployee * [], int );
void displayEmployees( SalariedEmployee * [], int );
int main()
{
int count = 0;
int selection = 0;
cout << fixed << setprecision( 2 );
SalariedEmployee *employees[ array_size ];


Where is the end of 'main'? Do you understand the concept of posting
_complete_ code? Yes, the rest of 'main' is probably irrelevant, but
you are supposed to have at least the closing curly brace there, no?

V
Dec 16 '05 #10
mini_t wrote:
thanks for the advice about arrays, here's Salaried.h
#ifndef SALARIED_H
#define SALARIED_H

#include "Employee.h" // Employee class definition

class SalariedEmployee : public Employee {

public:
SalariedEmployee( string &, string &, string &, double
= 0.0 );

void setWeeklySalary( double );
double getWeeklySalary();

void print(); // displays "Salaried employee: "

private:
double weeklySalary;

} // end class SalariedEmployee
^^^^

Just like I said. A class definition _ends_ with a _semicolon_ !
#endif // SALARIED_H
and Employee.h
[...]

Dec 16 '05 #11
thanks, I have to stop relying on the template code that comes with my
course

Dec 16 '05 #12
On 16 Dec 2005 07:03:16 -0800, "mini_t" <se*************@gmail.com>
wrote:
I hope I'm not annoying anyone here with this kind of newbie question,
anyway here it is:
What is wrong with this code here?

const int ARRAY_SIZE = 10;

gcc says: error: two or more data types in declaration of 'ARRAY_SIZE'

I've checked a few other sites and that confirmed that there isn't
really anything wrong with it at first glance.
This happened on a Mac with OS X 10.4.3 and this version of gcc:
powerpc-apple-darwin8-gcc-4.0.0
and also on a i586 running SuSE 10.

Thanks in advance for your help

Just for the record:

There are some compiler specific headers which have a line similar to
the following:

#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])

This might be the source of your problem.

Try to use another name for your array size.

regards,

-- Zara
Dec 16 '05 #13
mini_t wrote:
thanks for the advice about arrays, here's Salaried.h
[redacted]
and Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include <string> // required to access string functions

using namespace std; // for accessing C++ Standard Library members
Never, EVER do this. Never put "using namespace std;" in a header file.
If you need to use namespace std, the put it in your .cpp file.
[redacted]
#endif // EMPLOYEE_H

Dec 16 '05 #14
On 16 Dec 2005 08:19:10 -0800, "mini_t" <se*************@gmail.com>
wrote:
thanks, I have to stop relying on the template code that comes with my
course


If your course gives example code like that, it's at least 8 years out
of date. Buy a good book, and only write code like that to appease
your instructors and get a good grade.
Dec 16 '05 #15
Victor Bazarov <v.********@comacast.net> wrote:
Marcus Kwok wrote:
mini_t <se*************@gmail.com> wrote:
const int ARRAY_SIZE = 10;

gcc says: error: two or more data types in declaration of 'ARRAY_SIZE'


My first inclination is that ARRAY_SIZE is some macro that is #define'd
somewhere.


If it were true, the error wouldn't have 'ARRAY_SIZE' spelled out, it
would have the substituted text there, I think.


Oh, you're probably right, as the preprocessor should be invoked before
the compiler.

--
Marcus Kwok
Dec 16 '05 #16

Nick Keighley wrote:
[snip]

it looks ok to me. So if wierd things seem to be happening then suspect
the
preprocessor. Try


In my experience, I have never found a bug in the preprocessor nor in
the compiler. Every time my code (or the compilation of my code)
presented surprising results, it was my fault. Thus I try to find the
mistake among my own writings (and it is allways there) before I start
to think the problem is in the compiler.
If you can't spot the problem and still suspect the problem is the
compiler, try another compiler before doing "magic" with your code.
Magic is never the answer.

HTH,

Marcelo Pinto

Dec 16 '05 #17

Marcelo Pinto wrote:
Nick Keighley wrote:
[snip]

it looks ok to me. So if wierd things seem to be happening then suspect
the
preprocessor. Try


In my experience, I have never found a bug in the preprocessor nor in
the compiler. Every time my code (or the compilation of my code)
presented surprising results, it was my fault. Thus I try to find the
mistake among my own writings (and it is allways there) before I start
to think the problem is in the compiler.
If you can't spot the problem and still suspect the problem is the
compiler, try another compiler before doing "magic" with your code.
Magic is never the answer.


It possible that by "suspect the preprocessor", Nick Keighly did not
mean "suspect the preprocessor has a bug and is responsible for your
problem" but instead meant "suspect the preprocessor is performing
precisely as intended and somehow mangling your code so that what you
see on the screen and what the compiler sees are not the same thing"

That's how I read it.

Gavin Deane

Dec 17 '05 #18
de*********@hotmail.com wrote:
Marcelo Pinto wrote:
Nick Keighley wrote:
it looks ok to me. So if wierd things seem to be happening then suspect
the preprocessor. Try


In my experience, I have never found a bug in the preprocessor nor in
the compiler.
actually I *have* encountered compiler bugs. Though admittedly very
very rarely.

Every time my code (or the compilation of my code)
presented surprising results, it was my fault. Thus I try to find the
mistake among my own writings (and it is allways there) before I start
to think the problem is in the compiler.
indeed this is my default position
If you can't spot the problem and still suspect the problem is the
compiler, try another compiler before doing "magic" with your code.
Magic is never the answer.


It possible that by "suspect the preprocessor", Nick Keighly did not
mean "suspect the preprocessor has a bug and is responsible for your
problem" but instead meant "suspect the preprocessor is performing
precisely as intended and somehow mangling your code so that what you
see on the screen and what the compiler sees are not the same thing"

That's how I read it.


yes, that is what I meant. Else-thread I have been shown to be wrong.
--
Nick Keighley

Dec 17 '05 #19

red floyd wrote:
using namespace std; // for accessing C++ Standard Library members


Never, EVER do this. Never put "using namespace std;" in a header file.
If you need to use namespace std, the put it in your .cpp file.


Why not? (I'm not arguing -- I just believe that the reasons would be
interesting (to me).)

I don't understand the difference in meaning between .h files and .cpp
files although this lack of understanding hasn't (so far) affected my
ability to program. I put class definitions and function prototypes in
..h files and everything else in .cpp files. But that doesn't tell me
what the conceptual difference is. Yes, I know I could do a google
search and resolve all this. But since you did give an injunction:
"Never, EVER do this.", the onus is arguably on you to also give
reasons for following your advice.

Paul Epstein

Dec 17 '05 #20

pa**********@att.net wrote in message
<11*********************@z14g2000cwz.googlegroups. com>...

red floyd wrote:
> using namespace std; // for accessing C++ Standard Library members


Never, EVER do this. Never put "using namespace std;" in a header file.
If you need to use namespace std, then put it in your .cpp file.


Why not? (I'm not arguing -- I just believe that the reasons would be
interesting (to me).)

I don't understand the difference in meaning between .h files and .cpp
files although this lack of understanding hasn't (so far) affected my
ability to program. I put class definitions and function prototypes in
.h files and everything else in .cpp files. But that doesn't tell me
what the conceptual difference is. Yes, I know I could do a google
search and resolve all this. But since you did give an injunction:
"Never, EVER do this.", the onus is arguably on you to also give
reasons for following your advice.
Paul Epstein


#include <iostream>
#include <ostream>
#include <sstream>
// using namespace std;
std::ostringstream cout;

int main(){
int aNum(43);
cout << aNum << std::endl;
std::cout << cout.str() <<std::endl;
return 0;
}

Now uncomment the 'using *' line and see what your compiler tells you. Yeah,
you could use a different name for the stringstream, and go change it in the
million-plus lines in the project that used it, BUT, why should you have to
do that!?!?!

If you put 'using namespace std;' in a header, and that header gets included
in other headers/TUs in the project, you open the std space in the whole
project. Some programmer in Portland will be calling another project
programmer in Maine with many bad words because his code just got trashed.

Do you know **every** word/name in the std namespace? Avoid name clashes,
don't use 'using' in that way.

See the FAQ(s) for more.
--
Bob R
POVrookie
Dec 17 '05 #21

Nick Keighley wrote:
It possible that by "suspect the preprocessor", Nick Keighly did not
mean "suspect the preprocessor has a bug and is responsible for your
problem" but instead meant "suspect the preprocessor is performing
precisely as intended and somehow mangling your code so that what you
see on the screen and what the compiler sees are not the same thing"

That's how I read it.


yes, that is what I meant. Else-thread I have been shown to be wrong.
--
Nick Keighley


I misunderstood your message. My fault. :(

Marcelo Pinto

Dec 19 '05 #22
Marcelo Pinto wrote:
Nick Keighley wrote:

It possible that by "suspect the preprocessor", Nick Keighly did not
mean "suspect the preprocessor has a bug and is responsible for your
problem" but instead meant "suspect the preprocessor is performing
precisely as intended and somehow mangling your code so that what you
see on the screen and what the compiler sees are not the same thing"

That's how I read it.


yes, that is what I meant. Else-thread I have been shown to be wrong.


I misunderstood your message. My fault. :(


<shrug> no problem, I probably could have been clearer
--
Nick Keighley

Dec 19 '05 #23

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gabriel Afana | last post by:
I have a simple php script to just send email.....When I first load the script in a browser...it sends 2 emails. Why?? The weird thing is then when I refresh the page, it send only one email...I...
3
by: redneck_kiwi | last post by:
Hi all: I have a really weird problem. I am developing a customer catalog system for my company and as such have delved into sessions for authentication and access levels. So far, I have managed...
0
by: LRW | last post by:
I manage our mySQL database through putty (SSH terminal client). And whenever I do a select * from the table that contains ENCODEd passwords, the funky characters do funky things with the display....
1
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the...
0
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the...
6
by: Unicorn | last post by:
I can only say this is a weird problem! I will be sitting there typing away in the code window, when the whole IDE just vanishes without a trace. I get no error messages and no indication, it...
82
by: nobody | last post by:
Howdy, Mike! mikecoxlinux@yahoo.com (Mike Cox) wrote in message news:<3d6111f1.0402271647.c20aea3@posting.google.com>... > I'm a C++ programmer, and have to use lisp because I want to use >...
13
by: Dmitry Tkach | last post by:
Hi, everybody! Here is a weird problem, I ran into... I have two huge (80 million rows each) tables (a and b), with id as a PK on both of them and also an FK from b referencing a. When I try to...
3
by: aling | last post by:
Execute following T-SQL within Queary Analyzer of SQL Server 2000: ======================================= DECLARE @dTest DATETIME SET @dTest='2001-1-1 1:1:1:991' SELECT @dTest SET...
0
by: P Pulkkinen | last post by:
Dear all, sorry, i know this code is far little too long to debug here, but there is really annoying logical error. If someone debugs this, I really offer warm virtual handshake. What this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.