Question

What is #pragma once used for?

I have found the following code when refactoring:

#ifndef TARGET_OS_LINUX
#pragma once
#endif

Can anyone help me understand #pragma once?

What, when, where, and why is it used? Do you have an example?

 45  12393  45
1 Jan 1970

Solution

 48

#pragma is just the prefix for a compiler-specific feature.

In this case, #pragma once means that this header file will only ever be included once in a specific destination file. It removes the need for include guards.

2009-08-11

Solution

 18
  • What -- it is header guard. This file will be included only once.
  • When -- at a compile process
  • why -- to avoid double including.

"Header guards are little pieces of code that protect the contents of a header file from being included more than once."

2009-08-11