#pragma after compiler support

Can someone tell me a workaround to support #pragma once for various compilers?

I want to use something like in my header:

 #if _MSC_VER > ... || __GNUC__ > ... || ... #pragma once #endif 

Perhaps it already exists in boost sources or in your code?

+6
source share
2 answers

Use enable guards :

 #ifndef MY_HEADER_H #define MY_HEADER_H // ... #endif // MY_HEADER_H 

Sometimes you will see them in combination with #pragma once :

 #pragma once #ifndef MY_HEADER_H #define MY_HEADER_H // ... #endif // MY_HEADER_H 

#pragma once pretty widely supported .

+12
source

#pragma once is a non-standard alternative to enabling guards:

 #ifndef HEADER_H #define HEADER_H //contents of header #endif 

Both ensure that the contents of the header are not inserted more than once in the same translation block.

+5
source

Source: https://habr.com/ru/post/923901/


All Articles