General Development

Header file headers? – jestermax

jestermax

Member

Posts: 1064
From: Ontario, Canada
Registered: 06-21-2006
hey, i've been seeing a lot of #pragma once in header files lately. is there an advantage/disadvantage to using that over the "#ifndef blah, #define blah, #endif" structure?
dartsman

Member

Posts: 484
From: Queensland, Australia
Registered: 03-16-2006
I actually now put both... just as the compiler can discard the #pragma once if need be... There would be no performance boost at run-time (obviously ), however possibly could do something to help with compile times, though would be different on each compiler.

There is no harm (that I know of) in putting both.

------------------
www.auran.com

[This message has been edited by dartsman (edited February 22, 2007).]

jestermax

Member

Posts: 1064
From: Ontario, Canada
Registered: 06-21-2006
ok, i just looked it up:
"#pragma once" is microsoft only (as i suspected). if you want portable code then use the "ifndef" clause instead. so sad #pragma once is so much faster to type then #ifndef EXTREMELY_LONG_CLASS_NAME
SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
Woah! What a trip. Thanks for the info Jestermax. I think pragma once was introduced with VS 2003. I thought, "This is SO cool and easy." Now I may think twice about using it.
dartsman

Member

Posts: 484
From: Queensland, Australia
Registered: 03-16-2006
yeah, I still believe that you can have it in your code on other compilers though... just that it will disregard it on some compilers...

Anywho, it would be good to find out if other compilers will throw a warning on it or not.

------------------
www.auran.com