Possible Duplicate:
#pragma once vs include guards?
When should I use #pragma once
?
When should I use #ifndef HEADER_H_INCLUDED
?
The difference is that the latter is C and the former is not. Never use #pragma once
; always use #ifndef
.
One other thing to note when using the #ifndef
method is that any preprocessor symbol beginning with two underscores or an underscore followed by a capital letter is reserved and cannot be used. You should use things like #ifndef MYHEADER_H
and not #ifndef _MYHEADER_H
.
The construct
#ifndef MYFOO_H
#define MYFOO_H
/* header information for myfoo.h */
#endif
belongs in every header-file. The trick is: you can include a header file (accidentally) more than once without thinking abaout double declarations. so this is for the preprocessor.
The #pragma is for the compiler, and a preprocessor should ignore pragmas it does not understand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With