help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unique identifiers for guard macros


From: Angel Tsankov
Subject: Re: unique identifiers for guard macros
Date: Wed, 5 Apr 2006 20:20:26 +0300

Why do you need unique guards? The reason why header guards are used is
to prevent multiple inclusion of a file so the macros are based on the
file name.

For example, foo.h would have:

#ifndef FOO_H
#define FOO_H

#endif

Sorry if this isn't very helpful, but I don't see why you would need
unique guards.

Regards,

Ryan Mansfield


FWIW, I think that MS agrees with you: in VC++, you can write
#pragma once
at the top of a file instead of guards.

I guess that g++ is more hesitant to extend the language (for which MS is notorious). Since the preprocessor can do the trick (through unique guards), then that's that. Generating unique names sure is annoying, though. I try to include into the guard some information that includes both the file name, and the directory structure relative to the project's base directory.

Come to think of it, it seems that g++ supports #pragma once as well:
http://gcc.gnu.org/gcc-3.4/changes.html

That should solve your problem, no?

Hmm, interesting...
I thought g++ did not support #pragma once. I tested it on g++ 3.4.4 and 4.0.0 
and it works!
I think this is a very efficient solution, even more - in my opinion, it should 
be adopted by the standard.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]