What is the difference between #pragma and #ifndef?

Possible duplicate:
#pragma once vs includes defenders?

When should I use #pragma once?

When should I use #ifndef HEADER_H_INCLUDED?

+5
source share
4 answers

# ifndef / # define / # endif trick works on any C compiler, and on some of them speeds up the compilation process. The #pragma trick is non-standard and works only with a few C compilers and can lead to different semantics in those that do not support it.

+10
source

The difference is that the latter is C and the former is not. Never use #pragma once; always use #ifndef.

, #ifndef, , , , , . , #ifndef MYHEADER_H #ifndef _MYHEADER_H.

+2

#pragma, ( ) #pragma FP_CONTRACT -CX_LIMITED_RANGE-, .

#ifndef ilk, C ( ++) , , .

#pragma, C ( ++), . #pragma once , #pragma. , . #ifndef .

+1

myfoo.h

#ifndef MYFOO_H
#define MYFOO_H

/* header information for myfoo.h */

#endif

. , () , . .

#pragma is for the compiler, and the preprocessor should ignore pragmas that it does not understand.

0
source

All Articles