pragma 指令

 pragma 指令


Each implementation of C and C++ supports some features unique to its host machine or operating system. Some programs, for instance, need to exercise precise control over the memory areas where data is placed or to control the way certain functions receive parameters. The #pragma directives offer a way for each compiler to offer machine- and operating system-specific features while retaining overall compatibility with the C and C++ languages. Pragmas are machine- or operating system-specific by definition, and are usually different for every compiler.


#pragma 指令提供了一種方法,讓每個編譯器提供與機器和作業系統特定的功能,同時保留與 C 和 C++ 語言的相容性。#pragma 指令是機器或作業系統專有的,而且每個編譯器的都不一樣。


簡單來說,#pragma 是下給 compiler 看的指令,一些較常用的指令通常都支援跨平台的使用,所以大部份 compiler 都會看得懂。


對像我一樣使用 visual studio 的人來說,直接看MSDN是最快的了。

http://msdn.microsoft.com/en-us/library/d9x1s805(v=VS.71).aspx


我自己常用的

#pragma pack(1)

#pragma once //寫在.h檔裡,可以只編譯一次

#pragma warning(disable : 4996) //這有很多種用法,這是我常用的

#pragma comment(lib,"Ws2_32.lib") //使用函式庫,comment用法很多,也很複雜…

留言

這個網誌中的熱門文章

MSVC 與 CRT 之間的恩怨情仇

EXCEL VBA

演員筆記