1

I have been observing in some of the headers the use of pragma. But really not sure proper usage of it. Help in this really appreciated

#pragma once
#pragma warning ( disable : 4251 )
#pragma warning ( pop )
#pragma warning ( push )
#pragma comment(lib, "dbghelp")
#pragma warn -ccc 
#pragma warn -aus 
#pragma warn -csu 
#pragma warn -spa
pragma pack(push,8)
__cplusplus

Thanks in advance.

Anirban Roy
  • 111
  • 1
  • 1
  • 9
  • See the following for general use of `#pragma` http://stackoverflow.com/questions/232785/use-of-pragma-in-c – Toby Dec 19 '16 at 13:21
  • The specific use will depend upon your compiler. For GCC the documentation is available at https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html – Toby Dec 19 '16 at 13:21
  • Or here for MSVC: https://msdn.microsoft.com/en-us/library/d9x1s805.aspx – Toby Dec 19 '16 at 13:23

1 Answers1

-1

The preprocessor #pragma is basically used to change the execution order of the program that is a normal c/c++ program starts from main() and exits from main() but #pragma allows that to be changed.

the #pragma is divided as follows:-

#pragma startup < function name without brackets >:-

changes the start function that means this function will run before execution of main()

#include...
 void fun1();
 void fun2();
 #pragma startup fun1
 #pragma exit fun2
 int main()
{
...
}

#pragma exit < function name without brackets >:-

changes the exit function that means this function will run after execution of main()

#include...
 void fun1();
 void fun2();
 #pragma startup fun1
 #pragma exit fun2
 int main()
{
...
}

#pragma warn < -type of warning > :-

this directive tells the compiler whether or not we want to suppress a specific warning.

#include...
  #pragma warn -rvl // return value
  #pragma warn -par // parameter not used
  #pragma warn -rch // unreachable code

 void fun(int n)
  {
   ...
     //Do something
  } 

int main()
 {
 ...
 // Do something
 fun(); // parameter not used warning suppressed.
}

There are many other pragma directives and you can easily find them just by doing an in-depth and proper search on google.

NeoR
  • 353
  • 2
  • 9
  • 27
  • vote up and accept the answer if you feel satisfied. – NeoR Oct 29 '16 at 06:46
  • This does not answer the question at all! The OP asked about `#pragma once`, `#pragma warning`, `#pragma comment`, `#pragma warn` and `pragma pack`, yet you have described `#pragma startup`, `#pragma exit` and `#pragma warn` – Toby Dec 19 '16 at 09:30
  • @Toby he is just asking about pragma and has copied the content of a header file "I have been observing in some of the headers the use of pragma. But really not sure proper usage of it" – NeoR Dec 19 '16 at 13:04
  • See my comments to the OP – Toby Dec 19 '16 at 13:22
  • Yeah I read that but there was no mention of pragma warning so I just answered it, also I am not a gold tag holder who could mark it as duplicate . – NeoR Dec 19 '16 at 13:33