Is this an invalid program? Doesn't compile on my system

E

Eric Lilja

Is this an invalid program? Doesn't compile on my system:
#include <cstdio>

class Why
{
enum TArch {LITTLE_ENDIAN, BIG_ENDIAN, NON_IEEE};
TArch Architecture;
};

int
main()
{
Why ohwhy;
}

$ g++ -Wall -W -ansi -pedantic -c whynotwork.cpp
whynotwork.cpp:5: error: expected identifier before numeric constant
whynotwork.cpp:5: error: expected `}' before numeric constant
whynotwork.cpp:5: error: expected unqualified-id before numeric
constant
whynotwork.cpp:6: error: `TArch' does not name a type
whynotwork.cpp:6: error: extra `;'
whynotwork.cpp:7: error: expected declaration before '}' token

/ E
 
A

Alf P. Steinbach

* Eric Lilja:
Is this an invalid program? Doesn't compile on my system:
#include <cstdio>

class Why
{
enum TArch {LITTLE_ENDIAN, BIG_ENDIAN, NON_IEEE};
TArch Architecture;
};

int
main()
{
Why ohwhy;
}

It certainly looks like a valid program, although the uppercase symbols
might be problematic if there are existing macros with those names.

$ g++ -Wall -W -ansi -pedantic -c whynotwork.cpp
whynotwork.cpp:5: error: expected identifier before numeric constant

This indicates that at least one of your uppercase symbols is #define'd
whynotwork.cpp:5: error: expected `}' before numeric constant
whynotwork.cpp:5: error: expected unqualified-id before numeric
constant
whynotwork.cpp:6: error: `TArch' does not name a type
whynotwork.cpp:6: error: extra `;'
whynotwork.cpp:7: error: expected declaration before '}' token

T:\> g++ -Wall -W -ansi -pedantic -c vc_project.cpp
vc_project.cpp: In function `int main()':
vc_project.cpp:12: warning: unused variable 'ohwhy'

T:\> g++ --version
g++ (GCC) 3.4.4 (mingw special)
 
J

James Bannon

Eric said:
Is this an invalid program? Doesn't compile on my system:
#include <cstdio>

class Why
{
enum TArch {LITTLE_ENDIAN, BIG_ENDIAN, NON_IEEE};
TArch Architecture;
};

int
main()
{
Why ohwhy;
}

$ g++ -Wall -W -ansi -pedantic -c whynotwork.cpp
whynotwork.cpp:5: error: expected identifier before numeric constant
whynotwork.cpp:5: error: expected `}' before numeric constant
whynotwork.cpp:5: error: expected unqualified-id before numeric
constant
whynotwork.cpp:6: error: `TArch' does not name a type
whynotwork.cpp:6: error: extra `;'
whynotwork.cpp:7: error: expected declaration before '}' token

/ E
Compiles fine with GCC 4.1.1 20060525 (Red Hat 4.1.1-1) and I think it's valid C++.
What version of GCC are you using?

Jim.
 
C

Cy Edmunds

Eric Lilja said:
Is this an invalid program? Doesn't compile on my system:
#include <cstdio>

class Why
{
enum TArch {LITTLE_ENDIAN, BIG_ENDIAN, NON_IEEE};
TArch Architecture;
};

int
main()
{
Why ohwhy;
}

$ g++ -Wall -W -ansi -pedantic -c whynotwork.cpp
whynotwork.cpp:5: error: expected identifier before numeric constant
whynotwork.cpp:5: error: expected `}' before numeric constant
whynotwork.cpp:5: error: expected unqualified-id before numeric
constant
whynotwork.cpp:6: error: `TArch' does not name a type
whynotwork.cpp:6: error: extra `;'
whynotwork.cpp:7: error: expected declaration before '}' token

/ E

I see nothing wrong with your code. It compiled on VC7. By the way, thanks
for reducing your problem code to a very minimal level. Wish everybody did
that.

I suggest you try changing the name of the enumerated values. You may have
some sort of name collision.

Cy
 
E

Eric Lilja

Eric said:
Is this an invalid program? Doesn't compile on my system:
#include <cstdio>

class Why
{
enum TArch {LITTLE_ENDIAN, BIG_ENDIAN, NON_IEEE};
TArch Architecture;
};

int
main()
{
Why ohwhy;
}

$ g++ -Wall -W -ansi -pedantic -c whynotwork.cpp
whynotwork.cpp:5: error: expected identifier before numeric constant
whynotwork.cpp:5: error: expected `}' before numeric constant
whynotwork.cpp:5: error: expected unqualified-id before numeric
constant
whynotwork.cpp:6: error: `TArch' does not name a type
whynotwork.cpp:6: error: extra `;'
whynotwork.cpp:7: error: expected declaration before '}' token

/ E

Turns out these macros are defined in <sys/types.h> and that header is
included by Cygwin's <stdio.h>. If I compile it with -mno-cygwin, the
problem disappears. Anyway, I'm getting off-topic now that we've
established that there's nothing wrong with the code as far as the
standard is concerned, I just thought you might wanted to know what
platform I was using. And I was under the impression that
implementation stuff was supposed to begin with double underscores but
oh well...

Thanks to all that replied.

/ E
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top