Jump to content
  • Advertisement
Sign in to follow this  
wendigo23

#ifndef/#define or #pragma once?

This topic is 5443 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

Looks like gnu preprocessor looks for include guards in first line of a file if it there it marks a include only once.
But if you have don't have the first line #ifndef SOMETHING
it is not mark and will be include again.

Did some checking on Sun proeprocessor and it does the same. Cool :)

So what I said before, for newer preprocessor dose not need to be done.
Just have reg. inlcude guards is all that is needed.

Lrean something new today.

One thing to be careful, don't have two files use the same include guards.

Lord Bart :)

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Lord Bart
Form what I found out is.
Leading 2 underscore are reserved for compiler implementation.
Never use.
Single leading followed by a digit or upper case letter is reversed for system use.
ie include files provide by the OS.
Single underscore followed by lower case letter is allowed in user name space but not global (ie std).

I have had no problem with leading _ because I don't name my files after OS provided includes.


I couldn't remember the exact specification of it, but it's generally not a good idea to start with leading underscores because of issues like this.

Quote:

That's not to say its totaly right to do, it is just something I do.


This is what I don't understand, even when people know of the problem of using underscores, they still use them because everyone else does. What's the problem with just using something like "INCLUDE_GUARD_NAMESPACE_CLASSNAME"? Why do people put leading underscores for include guards?

Share this post


Link to post
Share on other sites
Quote:
Original post by wendigo23
(...), and instead to use #pragma once because its more crap for the compiler to parse. (emphasis mine)


That's bullshit in the first place. The compiler will see neither ifndefs nor pragmas because they're handled by the preprocessor. The preprocessor does simple stuff like text replacement, it doesn't even know C(++) syntax. If the preprocessor finds a false condition, it can pretty well ignore anything but opening and closing other conditionals until it finds the matching #endif.

Share this post


Link to post
Share on other sites
Quote:
Original post by wendigo23
Someone at my company just sent an email to everyone saying to stop using the #ifndef/#define combo to guard headers, and instead to use #pragma once because its more crap for the compiler to parse. HAHAHA right, like using a pragma vs a ifndef is going to take a lot less time to build.


Sounds about as smart as going on a diet to increase the fuel efficiency of your car by carrying less weight.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord Bart
[...]What if the included file needs to be included more then once.
Don't know why off the top of my head, but it just might.
So what do you do.
Each #include open and parse the file.[...]
Hrrmm, I wonder if a problem I was having not too long ago is related to this:
I have a class that requires window.h (some parts implemented in the header that use windows functionality), but it requires not only windows functionality but Windows 2000+ functionality so you have to define the windows version before including windows.h

In a file that uses this object, it uses windows functionality but just generic win95+ stuff so it just included windows.h then the above object.h

However, the win2000+ functions were not getting defined in the object.h for some reason(it defined the winver if not defined and #error-ed out if it was already defined too low), and I'm not sure if it is because windows.h improperly uses inclusion guards (so that even if defined mean it should have new things it just doesn't get included after the first windows.h include), or maybe it could be a bug in MSVCs detection of inclusion guards. Either way, it sucks to have inclusion order requirements. I guess I could prototype the functions myself in the object.h, but that isn't much better imo.

Quote:
Original post by seanw
[...]This is what I don't understand, even when people know of the problem of using underscores, they still use them[...]
Meh, people know the problems associated with tobacco and other drug use yet production of either is still a multi(m|b|tr)illion dollar business

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!