All of my header files include safeguards as well as pragma:
#pragma once
#ifndef FILE_NAME_H
#define FILE_NAME_H
class foo
{
};
#endif
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
{
};
#endif
I want to provide pragma once as an option to possibly speed up compilation and avoid name clashes, while maintaining compatibility between compilers.
source
share