Re: include guards

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

 



Hello Shriramana,


On Fri, 15 Jun 2007 09:13:59 +0530 Shriramana Sharma <samjnaa@xxxxxxxxx> wrote:

> Hello.
> 
> To prevent header files from being included more than once in the same 
> translation unit, we use include guards like
> 
> # ifndef FOO_H
> # define FOO_H
> ...
> # endif
> 
> Recently I came to know that I can use simply:
> 
> # pragma once
> 
> instead of the above group of sentences and the desired effect is still 
> accomplished.
> 
> This leads me to think of two things:
> 
> 1. why use the ifndef-define-endif method when the pragma once method is 
> simpler and cleaner?
> 
> 2. why should we need to use either method at all? If it is a 
> universally undesirable behaviour that the same header file is included 
> in a translation unit more than once, then an intelligent compiler (or 
> preprocessor) itself can by default take of this, right?
> 
> I understand that to write portable code that compiles on 
> not-so-intelligent compilers, we may need to do something manually, so 
> question 2 is answered, but question 1 still stands...

#pragma is simply not supported by all pre-processors, is that
directive present in any standard at least?


Regards,

-- 
wwp

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux