All of my header files use include guards as well as pragma once:
#pragma once
#ifndef FILE_NAME_H
#define FILE_NAME_H
class foo
{
//foo interface..
};
#endif /* FILE_NAME_H */
I understand that pragma once is not standard and may not be the same across compilers, but is there any chance it will cause and error? Would it be better to somehow test if it's 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-clashing, while still providing compatibility across compilers.