with -compat=5 of CC 5.4 error with version as structure tag

S

sreak

Need to find the cause of the following error:

The sample code goes as follows:( file name version.cpp )
#include <iostream>
struct version
{
int val;
};

int main()
{
version Test;
Test.val=0;
return (0);
}

Compilation environment:
Sun Forte 7 Developer, CC version 5.4

Observation:
* /opt/SUNWspro/bin/CC version.cpp ( By default the -compat is 5 )
"version.cpp", line 3: Error: version is not a structure tag.

* /opt/SUNWspro/bin/CC -compat version.cpp ( This means -compat=4 )
No Error, compilation suzzessful

* When you don't include <iostream>, there is no problem with -compat=5
also.

* When any other structure tag is used, thgere is no error.

Is it because there is some funtiion, datatype already included in
the standard library with the name "version"? C++ puts the structure
tags and other dataTypes in same namespace.
 
M

Mike Wahler

sreak said:
Need to find the cause of the following error:

The sample code goes as follows:( file name version.cpp )
#include <iostream>

Nit: You're not using anything from this header.
struct version
{
int val;
};

int main()
{
version Test;
Test.val=0;
return (0);

Nit: 'return' is not a function. No parentheses are
required around the argument (but they're not prohibited either).

The above program is completeley valid standard C++, and
a compiler that rejects it does not conform to the standard.
Compilation environment:
Sun Forte 7 Developer, CC version 5.4

Observation:
* /opt/SUNWspro/bin/CC version.cpp ( By default the -compat is 5 )
"version.cpp", line 3: Error: version is not a structure tag.

* /opt/SUNWspro/bin/CC -compat version.cpp ( This means -compat=4 )
No Error, compilation suzzessful

* When you don't include <iostream>, there is no problem with -compat=5
also.

* When any other structure tag is used, thgere is no error.

Is it because there is some funtiion, datatype already included in
the standard library with the name "version"? C++ puts the structure
tags and other dataTypes in same namespace.

Your questions are about your compiler, not the language,
so not topical here.

Try consulting support resources for your compiler.

'version' is not a reserved word in C++, so a compiler
that won't let you use it in a conforming program is
broken or not configured to be standard-conforming.

-Mike
 

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,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top