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: Ulrich Eckhardt
Subject: Re: unique identifiers for guard macros
Date: Fri, 07 Apr 2006 17:56:50 +0200
User-agent: KNode/0.9.3

Angel Tsankov wrote:
> Can someone recommend a way to create "unique" identifiers for use 
> in guard macros: 
> 
> #if !defined (UNIQUE_GUARD)
> #define UNIQUE_GUARD

As you said, the most important thing is to not collide with any existing
one. The advise to use a GUID is a good one, another good one is to just
use the date when the file is started. I always leave a generic prefix
like the module and the filename in uppercase (just in case I need to
identify where it's coming from). 

BTW: you asked for a GUID tool - depending on the  system you have, you
don't need one, on most unixoid systems you can do this:

  dd if=/dev/urandom count=1 bs=10 | md5sum 

This reads ten bytes from a random-number generator and computes their MD5
hash - should be sufficiently unique. ;)

> #endif //!defined UNIQUE_GUARD
           ^^^^^^^^^^^^^^^^^^^^^
I'd recommend rather writing "include guard" there, because this comment
doesn't make it clear whether in the lines before this macro was defined -
after all, it could have had an #else somewhere in between. Other than
include guards, I also tend to indent such things:

#if foo
#  if bar
#    error foo and bar!
#  else
#    define baz
#  endif
#endif

I believe that this structure makes it clear what is evaluated when, much
better than any comment would do.

Uli

-- 
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/



reply via email to

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