Does "# pragma once" have the ability to cause errors?

All of my header files include safeguards as well as pragma:

#pragma once
#ifndef FILE_NAME_H
#define FILE_NAME_H

class foo
{
    //foo interface..
};

#endif /* FILE_NAME_H */

I understand that pragma is not standard once and may not be the same for compilers, but is there a chance of its occurrence and errors? Would it be better to somehow check if this is available first?

#ifdef THIS_COMPILER_SUPPORTS_PRAGMA_ONCE
    #pragma once
#endif

#ifndef FILE_NAME_H
#define FILE_NAME_H

class foo
{
    //foo interface..
};

#endif /* FILE_NAME_H */

I want to provide pragma once as an option to possibly speed up compilation and avoid name clashes, while maintaining compatibility between compilers.

+5
source share
2 answers

#pragma once , [Ref # 1] , #pragma once.

, - #pragma once, , , #pragma once, .


[Ref # 1]
++ 03: 16.6 Pragma

# pragma pp-tokensopt new-line

. , , .

+9

: " , , ", , , , #pragma.

+5

All Articles