By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jul 14 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Eric Lilja wrote:
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.
Jul 14 '06 #2

P: n/a
* 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
as a numeric constant by your <cstdio>.

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)
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 14 '06 #3

P: n/a

"Eric Lilja" <mi********@gmail.comwrote in message
news:11**********************@35g2000cwc.googlegro ups.com...
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
Jul 15 '06 #4

P: n/a

Eric Lilja wrote:
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.hand 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

Jul 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.