"#pragma once" for header files under GCC

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Knows some wx things
Knows some wx things
Posts: 35
Joined: Fri Mar 11, 2005 3:43 am

"#pragma once" for header files under GCC

Post by MrRage » Tue May 31, 2005 6:51 pm

I was looking at some MS generated source code (stdafx.h) and noticed that this file used "#pragma once" insted of "#ifndef _Deinfe_ #define _Define_ #endif" - pragma once is less work than the standard if not defined.. and id does the same job.

So can I use pragma once on a GNU compioler or is that an MSVC++ thing?

Super wx Problem Solver
Super wx Problem Solver
Posts: 398
Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel

Post by Avi » Tue May 31, 2005 6:59 pm

I believe it's Visual C++ specific macro... For a completely portable one use:

Code: Select all

#ifndef __FILENAME_H__
#define __FILENAME_H__


#endif // __FILENAME_H__

Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 203
Joined: Tue Aug 31, 2004 7:06 pm
Location: Behind a can of Mountain Dew

Post by eco » Tue May 31, 2005 10:25 pm

It is deprecated in GCC versions before 3.4. It was undeprecated in GCC 3.4. but it's more portable to use the standard inclusion cards like Avi showed although avoid putting two leading underscores before the name as those names are reserved for the compiler's interal usage according to the ANSI standard. Putting one is ok but is more often used as the names of library functions. Personally, I recommand just not putting underscores before the name on anything.

User avatar
Ryan Norton
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Thu Jun 02, 2005 7:25 am

eco wrote:Personally, I recommand just not putting underscores before the name on anything.
Yes, this is because technically (according to the standard I believe) names with underscores before them are supposed to be used by compiler vendors ONLY.... of course WX uses and abuses this like crazy...

Post Reply