Sign in to follow this  
lack o comments

error caused by variable '_DI'?

Recommended Posts

Now that I've switched from VC 6.0 to 8.0, I'm going over all my code libaries to make sure they work properly. In my DirectInput library I have a class typedefined as '_DI'.
typedef class DirectInput
{
//stuff
}_DI;
And when compiling I get the following errors:
warning C4091: 'typedef ' : ignored on left of 'DirectInput' when no variable is declared
error C2143: syntax error : missing ';' before 'constant'
error C2059: syntax error : 'constant'
error C2143: syntax error : missing ';' before '{'
error C2447: '{' : missing function header (old-style formal list?)
When I change '_DI' to anything else. There is no problem. So my question is: What is wrong with this identifier? Is it some kind of compiler switch or reserved word?

Share this post


Link to post
Share on other sites
SiCrane    11839
All identifiers starting with a leading underscore and a capital letter are reserved for the compiler implementaiton. Using them is not kosher (unless you are the compiler vendor).

Share this post


Link to post
Share on other sites
rip-off    10976
i believe all names starting in a _ are reserved for the implementation, but i've never seen it enforced with a compiler error. maybe it is used in that instance.

compiles under dev-cpp and mingw. i dont have directX headers and stuff though

EDIT: 3 mins behind. im getting slower

Share this post


Link to post
Share on other sites
SiCrane    11839
Names starting with _ are only reserved in the global namespace, you can use something beginning with an underscore followed by a lowercase letter, for example, in a class. (But again, _ followed by a capital non-kosher everywhere.)

Share this post


Link to post
Share on other sites
Not kosher. NOT KOSHER! I KNEW I shouldn't have been eating that thing! Curses! Err wait... nevermind.

But seriously:
Just out of curiosity: How long has that standard been around? And was this another 'MSVC 6-not-quite-conforming' issue? It worked fine on it.

Share this post


Link to post
Share on other sites
rip-off    10976
Quote:
Original post by SiCrane
Names starting with _ are only reserved in the global namespace, you can use something beginning with an underscore followed by a lowercase letter, for example, in a class. (But again, _ followed by a capital non-kosher everywhere.)


thanks. useful to know. i've seen it used a few times and was wondering why. is ther any reason to put an underscore like so? seems a bit arbitrary to me...

Share this post


Link to post
Share on other sites
SiCrane    11839
The standard has been around since 1998. Also, just because they are reserved for the compiler doesn't mean that the compiler will forbid you from using them. They're often used to implement the header files that the compiler ships, so the compiler itself won't diagnose their use because it doesn't know if what it's getting is from one of its own headers or from your code.

Share this post


Link to post
Share on other sites
SiCrane    11839
Quote:
Original post by rip-off
is ther any reason to put an underscore like so? seems a bit arbitrary to me...

I don't understand the question.

Share this post


Link to post
Share on other sites
Ah '98. That explains a bit.

Actually, in this case the compiler DOES forbid me from using it. At least as any kind of variable. I can still define with it though. Also, I found a header 'xlocinfo' with a defined constant called '_DI'. The comment said
/* SUPPLEMENTAL CTYPE MACROS & DECLARATIONS */



[EDIT]
Ack! Silly me. The compiler does allow it. I just forgot to test with a different variable name *duh :P
[/EDIT]

Share this post


Link to post
Share on other sites
rip-off    10976
Quote:

I don't understand the question.

i've seen people name their member varialbes with underscores. im just wondering why? is it some kind of "this is a member variable" marker, like the common
"m_" some people use.

not really important though.

Share this post


Link to post
Share on other sites
SiCrane    11839
Quote:
Original post by lack o comments
Actually, in this case the compiler DOES forbid me from using it.


What I was trying to say is that MSVC 6 wasn't broken (in this case) because it let you use the variable.

Quote:
Original post by rip-off
i've seen people name their member varialbes with underscores. im just wondering why? is it some kind of "this is a member variable" marker, like the common
"m_" some people use.


Yes, pretty much. Personally I use a trailing underscore to denote non-public member variables, but a leading underscore followed by a lowercase letter is also used by some people.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this