Whats the difference...

Started by
6 comments, last by DigitalDelusion 18 years, 9 months ago
...between inline _inline and __inline? In VC7 at least they are all keywords. How does the compiler/linker or whatever treat them differently?
Advertisement
MSDN
They are all treated exactly the same in C++.

inline is not a reserved keyword in C. Names starting with two underscores, like __inline, are reserved to the compiler implementers in both languages.

__inline is therefore provided for C programmers who want to use the inline feature, while guaranteeing nobody will have used that name, since it is out-of-bounds to ordinary programmers.

As the MSDN link xor posted indicates, _inline is provided for compatibility reasons (though it doesn't fall in the domain of reserved names).

This is the reason why even though only names starting with two underscores or one underscore and a capital letter are reserved, you should avoid using _ as a prefix unless you have a compelling reason (and "I like my naming scheme" isn't one such).
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
more specificly anything that _Looks like__this is reserved for the implementation, that is anything starting with underscore capital or containing a double underscore.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
Quote:Original post by Fruny
This is the reason why even though only names starting with two underscores or one underscore and a capital letter are reserved, you should avoid using _ as a prefix


I believe underscore followed by a lowercase letter is reserved as well, although only in the file scope (not in all scopes as per _Foo and __bar) (link).
Ok I understand.

I have another question, if inlining a function in a cpp file will cause a linking error, then why does the compiler even allow you to do it in the first place. This is really annoying. Now i have to go back and copy all my inline functions over to the header. Which believe looks ugly and un-organized having every thing crammed in to one file :( Plus it exposes my source code. Is there no way to get around this inconvenience.
If a function is inine, it becomes not a function as such, but only code included at the position where you called the function. So, the function also doesn't appear in the object file for that compilation unit.

If you then use the function in another compilation unit, you get a linker error, since the function nowhere exists in the object files.
Call the inline functions only in the source file use have defined them in, and there is no need to put them in the header files.
Quote:Original post by MaulingMonkey
Quote:Original post by Fruny
This is the reason why even though only names starting with two underscores or one underscore and a capital letter are reserved, you should avoid using _ as a prefix


I believe underscore followed by a lowercase letter is reserved as well, although only in the file scope (not in all scopes as per _Foo and __bar) (link).


Seems like that's an arbitary MS thing but since the rules are a bit obscure (judged from that Im the only one putting emphaisis on contains double underscore) I would say that the safe rule to tell people is to simply stay away from starting with an underscore altogheter and just hope that they don't even consider double underscore, that should be quite safe, I've never had the urge to use it.

Quote:
2.10 identifiers
2: In addition, identifiers containing a double underscore (_ _) or beginning with an underscore and an
uppercase
letter are reserved for use by C + + implementations and standard libraries and shall not be used
otherwise; no diagnostic is required.


HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats

This topic is closed to new replies.

Advertisement