#pragma Directive in C/C++

The #pragma is complier specified. for example, the code below does not work in gcc.

#pragma startup and #pragma exit:

#pragma startup func1 
#pragma exit func2 
    
void func1() 
{ 
    printf("Inside func1()\n"); 
} 
    
void func2() 
{ 
    printf("Inside func2()\n");    
} 
    
int main() 
{ 
    printf("Inside main()\n"); 
        
    return 0; 
}  

in GCC, you can use 

void __attribute__((constructor)) func1();  void __attribute__((destructor)) func2();     #pragma warn Directive in case there are some warning and you are sure it works as your expection and there is no any risk, you can use #pragma warn to disable it, but the code shall have a well document. 
#pragma warn +xxx (To show the warning)
#pragma warn -xxx (To hide the warning)
#pragma warn .xxx (To toggle between hide and show)

  • #pragma warn -rvl: This directive hides those warning which are raised when a function which is supposed to return a value does not return a value.
  • #pragma warn -par: This directive hides those warning which are raised when a function does not uses the parameters passed to it.
  • #pragma warn -rch: This directive hides those warning which are raised when a code is unreachable. For example: any code written after the return statement in a function is unreachable.

 

 

上一篇:Ubuntu安装后需要做的事


下一篇:解决1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'