Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is #pragma used for?

Tags:

c++

Can anyone help me understand #pragma?

ifndef TARGET_OS_LINUX #pragma once endif 

What,when, where, why, an example?

The above is in some code that I am refactoring....

like image 622
user147502 Avatar asked Aug 11 '09 23:08

user147502


2 Answers

#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.

like image 131
John Calsbeek Avatar answered Oct 14 '22 11:10

John Calsbeek


  • 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."

like image 31
f0b0s Avatar answered Oct 14 '22 11:10

f0b0s