Sign in to follow this  

Whats the difference...

This topic is 4531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

...between inline _inline and __inline? In VC7 at least they are all keywords. How does the compiler/linker or whatever treat them differently?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites

This topic is 4531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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