マクロ定義を使用して文字列を処理#pragma

19323 ワード

マクロ定義の使用には文字列化演算子である「#」演算子があり、マクロ定義後に現れる「#」演算子は、その後に得られるパラメータを1つの文字列に変換し、利点としてこのような使用法とも呼ばれる「#」を文字列化演算子と呼ぶ.例を次に示します.
#include 
#define PASTE(n)  "abcdefkj"#n
//C       
//             
using namespace std;


int main()
{
    int n = 16;

    printf("PASTE  = %s",PASTE(n));
    system("pause");      
    return 0;
}
#pragma once        //        
//#pragma once <==>  #ifndef    #define  #endif

class myTeacher // ctrl + shift +u         
{
public:
    myTeacher(void);

};

パラレルオペレータ
並列演算子である「##」演算子、「##」演算子はパラメータを結合するために使用され、前処理プログラムは「##」演算子の両側に現れるパラメータを1つの記号に結合する.次のようになります.
#include 
#define NUM(a,b,c)  a##b##c
#define STR(a,b,c) a##b##c

//C       
//             
using namespace std;


int main()
{

    printf("PASTE  = %d
"
,NUM(1,2,3)); printf("PASTE = %s
"
,STR("aa","bb","cc"));; system("pause"); return 0; }
#include 

//C       
//             

using namespace std;
#define CONFIG 0

#if defined CONFIG   //#if defined <==> #ifdef
void f()
{
    printf("ni hao!
"
); } #endif int main() { f(); system("pause"); return 0; }
   #ifndef <==> #if !defined
#error token  //         token
#pragma token   //              ,  token  ,        ,        ,          ,    #pragma once,            
message   
Message                      ,                 。      :
#pragma message("    ")
                             。
                        ,                      ,                      。                         _X86           
#ifdef _X86
#pragma message("_X86 macro activated!")
#endif
      _X86     ,                    “_X86 macro activated! ”。                           。
code_seg
          pragma   code_seg。   :
#pragma code_seg(["section-name"[,"section-class"]])
                  ,                  。
#pragma once
(    )
                             ,        VC6      ,                 。
#pragma once     ,            ,             ,        ,                      。
#ifndef,#define,#endif   C++    ,  C++       ,             。       C++            ,          ,        
#pragma hdrstop
#pragma hdrstop            ,            。BCB                ,                        ,               。
           ,    A    B,    B     A  。    #pragma startup       ,     #pragma package(smart_init) ,BCB              。
#pragma resource
#pragma resource "*.dfm"   *.dfm          。*.dfm          。
#pragma warning
#pragma warning(disable:450734;once:4385;error:164)#pragma warning(disable:450734)//   4507 34     
#pragma warning(once:4385)//4385          
#pragma warning(error:164)// 164           。
    pragma warning        :
#pragma warning(push[,n])
#pragma warning(pop)
  n        (1---4)。
#pragma warning(push)                。
#pragma warning(push,n)                ,            n。
#pragma warning(pop)             ,
                 。  :
#pragma warning(push)
#pragma warning(disable:4705)
#pragma warning(disable:4706)
#pragma warning(disable:4707)
//.......
#pragma warning(pop)
        ,           (  47054706 4707)。
#pragma comment
#pragma comment(...)
                         。
   lib   ,            。
         #pragma                     。  ,       :
#pragma loop_opt(on)//  
#pragma loop_opt(off)//  
  ,                         , “Parameter xxx is never used in function xxx”,    :
#pragma warn—100//Turnoffthewarningmessageforwarning#100
intinsert_record(REC*r)
{/*functionbody*/}
#pragma warn+100//Turnthewarningmessageforwarning#100backon
             100     ,          。
      #pragma     ,                    。           。
#pragma pack(n) #pragma pop()
struct sample
{
char a;
double b;
};
 sample     #pragma pack(n)   ,sample          ;
(           n ,         ,     a     n  a   n   ;
  a     n   a   ;)            16  .
 sample   #pragma pack(1)   ,sizeof(sample)=9  ;    。
(  : n  sample           ,n        。
   n   ,       ,    ;   )
#pragma apop()    #pragma pack(n)    ,            #pragma pack(n)
#pragma comment(comment-type,["commentstring"])
comment-type          ,       ,   compiler,exestr,lib,linker  。
comment string      comment-type          。
    :
1、compiler:
                   ,     linker   。
2、exestr:
          。
3、lib:
               ,        comment string(    Linker   lib      )        Object             ,linker                      。                 ,   object                 。                  ,  Z            object4、linker:
        ,                      。
     linker      Linker.

/DEFAULTLIB,/EXPORT,/INCLUDE,/MANIFESTDEPENDENCY,/MERGE,/SECTION
(1) /DEFAULTLIB:library
/DEFAULTLIB       library     LINK             。  /DEFAULTLIB                 .obj               。        (/NODEFAULTLIB)      /DEFAULTLIB:library。             library   ,    (/NODEFAULTLIB:library)       /DEFAULTLIB:library。
(2)/EXPORT:entryname[,@ordinal[,NONAME]][,DATA]
     ,         ,             。       。    DLL      。entryname                  。ordinal            1   65,535    ;       ordinal,  LINK      。NONAME            ,   entryname。
DATA             。             extern __declspec(dllimport)   。
          ,            :
      __declspec(dllexport).def      EXPORTS   LINK      /EXPORT                    。LINK                  ,         .exp   。
LINK           。       .obj         。   entryname              (         ),  LINK         。             ,  LINK       。              ,    Dumpbin               。
(3)/INCLUDE:symbol
/INCLUDE                    。
        ,             (,)、   (;)    。     ,          /INCLUDE:symbol。
                        symbol。                       。            /OPT:REF         。
        #pragma comment(lib,"*.lib")   。#pragma comment(lib,"Ws2_32.lib")    Ws2_32.lib   。            Ws2_32.lib     ,                               settings 
#pragma disable

        ,        。              。   C51     。
#pragma data_seg
  
 #pragma data_seg                ,      :
#pragma data_seg("shareddata")
HWNDsharedwnd=NULL;//    
#pragma data_seg()
-----------------------------------------------------------------
1#pragma data_seg()    DLL 。    , DLL               。     :                    ,            DLL      。
2,         ,                   .BSS  ,                 。  ,
#pragma data_seg("MyData")
intg_Value;//Notethattheglobalisnotinitialized.
#pragma data_seg()
//DLL        :
int GetValue()
{
    return g_Value;
}
void SetValue(int n)
{
    g_Value=n;
}
        A B,A B      DLL,  A   SetValue(5); B    int m = GetValue();   m      5,         。  DLL                   ,    ,     。    g_Value      ,  g_Value       MyData  。    ,  A   SetValue(5); B    int m = GetValue();   m      5,               。
#pragma region
#pragma region Visual C++         。             ,         ,        。             。                   。1
#pragma region name#pragma endregion comment#pragma region Variables
HWND hWnd; 
const size_t Max_Length = 20;

//other variables

#pragma endregion This region contains global variables.#pragma region #pragma endregion  。#pragma region #pragma endregion               。        ,             。
        :  Visual C++     、 、    ,                 ,#pragma region           “-” ,       ,  “-”    “+” ,           。
       Visual Studio 2005         。   Visual Studio 2005#pragma region      “1st”     ,   “error C2059: syntax error : 'bad suffix on number'”     。                        。[1] 
    (#pragma pack)  
        ,              。                     ,          ,         ,           。                   ,                     ,                。   ,       ,          ,                ,        ,    。   TCP      ,          。
         :
#pragma pack(1)//  1        
struct TCPHEADER
{
shortSrcPort;//16     
shortDstPort;//16      
intSerialNo;//32    
intAckNo;//32    
unsignedcharHaderLen:4;//4     
unsignedcharReserved1:4;//  16   4 
unsignedcharReserved2:2;//  16   2 
unsignedcharURG:1;
unsignedcharACK:1;
unsignedcharPSH:1;
unsignedcharRST:1;
unsignedcharSYN:1;
unsignedcharFIN:1;
shortWindowSize;//16     
shortTcpChkSum;//16 TCP   
shortUrgentPointer;//16     
};
#pragm apop()//  1      
#pragma pack       ,        :   ,  ,        ,        0   ,           ,  #pragma pack                 ,        。   , #pragma pack                   ,              。         ,                。