A mysterious undocumented keyword?

G

gil

Hi,

In VS 2005 (SP1), the following code does not compile:

=============
typedef int _sptr ;
_sptr p = 1;
=============

the compiler emits the following:

source1.cpp(1) : warning C4091: 'typedef ' : ignored on left of 'int'
when no variable is declared
source1.cpp(2) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int

After pulling half my hair out, I found that changing _sptr to almost
anything else (e.g. _sptr1), makes the code compile. Note that:
1. _sptr is not mentioned anywhere in the MSDN database.
2. I suspect that this didn't happen to me before upgrading my VS2005
to SP1.
3. Removing the '_' made the word 'sptr' change to blue as if a
keyword, again, sptr isn't mentioned in MSDN. (this happened on one
PC, on another it didn't).

Can anyone please help, what is _sptr?

Thanks,
Gil Moses.
 
N

Nathan Mates

typedef int _sptr ;

Anything starting with an _ is reserved for the compiler. See
http://www.mail-archive.com/[email protected]/msg78723.html , or
http://www.mozilla.org/hacking/portable-cpp.html#no_reserved_names
which quotes the C++ spec, section 17.4.3.1.2. Yes, a whole lot of
existing code violates this. No, this is not flagged as a warning,
though I think it should.

Short summary: you're violating C++ standards with your code
above. As you've already discovered, other names work. Use them.
Don't try to cry conspiracy or "hidden keyword" about _sptr, just do
the right thing and avoid leading underscores.

Nathan Mates
 
B

Ben Voigt

Nathan Mates said:
Anything starting with an _ is reserved for the compiler. See
http://www.mail-archive.com/[email protected]/msg78723.html , or
http://www.mozilla.org/hacking/portable-cpp.html#no_reserved_names
which quotes the C++ spec, section 17.4.3.1.2. Yes, a whole lot of
existing code violates this. No, this is not flagged as a warning,
though I think it should.

Short summary: you're violating C++ standards with your code
above. As you've already discovered, other names work. Use them.
Don't try to cry conspiracy or "hidden keyword" about _sptr, just do
the right thing and avoid leading underscores.

It's still reasonable to ask what the keyword does, especially if the editor
is highlighting "sptr" (no underscore) as a keyword.
 

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

Top