#pragma 키워드는 컴파일러 제작 회사가 특정 플랫폼에 의존하는 기능을 확장하기위해 기능을 추가한 키워드이다.
해당 컴파일러가 지시명을 인식하지 못한다면 에러 또는 경고 메세지를 수반하지 않고서 #pragma의 지시를 무시하게 된다.
#pragma 옵션
옵션 |
설명 |
allock_text |
|
comment |
코드 안에 특별한 주석을 기입함 |
init_seg |
|
optimize |
|
auto_inline |
|
component |
|
inline_depth |
|
pack |
변수 정렬을 인위적으로 변경 |
bss_seg |
|
data_seg |
다른 파일에서 데이터를 공유하고자할때 |
inLine_recursion |
|
pointers_to_members |
|
check_stack |
|
function |
|
intrinsic |
|
setlocale |
|
code_seg |
|
hdrstop |
|
message |
컴파일시 메시지를 출력함 |
vtordisp |
|
const_seg |
|
include_alias |
|
once |
해당 파일이 한번만 포함 |
warning |
컴파일러 경고 메시지를 만들거나 안보이게 함 |
link |
실행화일에 파일을 링크 |
#pragma once
ex> #pragma once
전처리기가 이 행을 처리하려고 할 때, 이 파일은 오직 한 번 추가되어야 한다는 것을 알게 된다.
#pragma pack
ex>
#pragma pack(n) //n으로 정렬방식을 바꾼다.
#pragma pack() //Default 정렬방식을 바꾼다.
#pragma pack(push, n) //n의로 정렬 방식을 바꾸고 기존정렬방식을 스택에 저장한다.
#pragma pack(pop) //스택에 저장한 정렬방식으로 다시 돌린다.
pack 지시자는 이 후 부터 선언되는 구조체의 정렬 방식을 지정하는 것이다. n은 컴파일러가 저장된 메모리에 데이터를 정렬하는 방법을 결정하는 byte의 크기이다.
ex>
#pragma pack(1)
typedef struct _TEST_STRUCT
{
char CharValue; //1byte
char CahrValue2; //1byte
int IntValue; //4byte
char* pCharValue; //4byte
int* pIntValue; //4byte
} TEST_STRUCT, *PTEST_STRUCT;
#pragma pack()
위 구조체를 sizeof() 로 구조체의 크기를 알아보면 문제가 있음을 알 수 있다. 위 구조체의 크기는 14byte이다. 하지만 sizeof()로 크기를 알아보면 16byte로 나타나는 것을 알 수 있다. 이 떄 pack을 사용하면 빈공간 없이 14byte로 구조체가 선언된것을 알 수 있다.
#pragma warning
ex>
#pragma warning (disable:4101) // 경고를 무시하도록 한다.
#pragma warning (once:4101) // 4101경고를 한 번만 출력한다.
#pragma warning (error:4700) // 경고 대신 에러를 출력한다.
#pragma warning (3:4706) // 4706번 경고를 레벨 3으로 올린다.
이 지시자는 컴파일시 나오는 경고를 설정한다. 이것으로 매 컴파일 마다 나오는 경고를 없애거나 한번만 나오게 할 수있다.
제어문 |
설명 |
once : 번호 |
반복되는 경고를 한 번만 출력한다. |
default : 번호 |
원래 설정대로 되돌린다. |
disable : 번호 |
경고를 출력하지 않는다. |
error : 번호 |
경고를 에러로 처리한다. |
level : 번호 |
경고의 레벨(1~4)을 변경한다. |
push[,n] |
모든 경고의 레벨을 저장한다. n이 있을 경우 저장과 동시에 전역 경고 레벨을 n으로 변경한다. |
pop |
스택에 마지막으로 저장된 경고 레벨을 복원한다. |
#pragma comment
ex>
#pragma comment(lib, "d3d8.lib")
이 지시자는 해당 옵션에 따라 다양한 주석문 및 문자를 코드에 추가한다.
옵션 |
설명 |
lib |
코드 내에서 명시적으로 라이브러리의 링크를 지정해준다 |
exestr |
기록된 string은 실행파일 내부에 기록되어지며, 이것은 결코 메모리로 load되지 않는다. 다만 파일 검색 유틸리티를 사용하여 실행파일에서 string을 찾아볼 수 있다. |
user |
".OBJ" file에 string을 기록합니다. 하지만 linker에 의해 string은 무시되어집니다. object 파일에만 그 내용이 남게 됩니다. |
#pragma data_seg
ex>
#pragma data_seg(".mine$a") //.mine 명으로 공유, Section 이름은 8자 또는 그 이하로 해야한다.
int g_nCount1 = 0;
#pragma data_seg(".mine$z") //'$' 기호 전에 동일 이름인 섹션들은 한 개의 섹션으로 통합이 된다. 여기서 통합의 순서는
'$'다음의 문자 정렬로 순서를 결정한다.
int g_nCount2 = 0;
#pragma data_seg() //Default로 복원
#pragma comment( linker, "/SECTION:.mine, RWS" ) // R:Read, W:Write, S:Shared
우선은 공유할 데이터(변수)를 Global 변수로 선언하고 #pragma data_seg를 위와 같이 추가한 다음 Linker 코드를 추가하면 g_nCount1과 g_nCount2데이터를 DLL 외부에서 공유할 수 있게 된다.
#pragma link
ex>
#pragma comment( linker, "/SECTION:.SHAREDATA, RWS" ) // R:Read, W:Write, S:Shared
이 지시자는 실행파일에 해당 파일을 Link 시킨다.
옵션 |
설명 |
/ALIGN:number |
Specifies the alignment of each section |
/BASE:{address | @filename,key} |
Sets a base address for the program |
/COMMENT:["]comment["] |
Inserts a comment string into header |
Creates debugging information | |
/DEBUGTYPE:CV |
Creates particular formats of debugging information |
/DEF:filename |
Passes a module-definition (.DEF) file to the linker |
/DEFAULTLIB:library |
Searches specified library when resolving external references |
Controls the delayed loading of DLLs | |
Causes the delayed loading of the specified DLL | |
Builds a DLL | |
/DRIVER[:UPONLY] |
Creates a Windows NT kernel mode driver |
/ENTRY:function |
Sets the starting address |
/EXETYPE:DYNAMIC |
Builds a virtual device driver |
Exports a function | |
/FIXED[:NO] |
Creates a program that can be loaded only at its preferred base address |
/FORCE[:{MULTIPLE|UNRESOLVED}] |
Forces link to complete in spite of unresolved or multiply defined symbols |
/GPSIZE:# |
Specifies the size of communal variables for MIPS and Alpha platforms |
/HEAP:reserve[,commit] |
Sets the size of the heap in bytes |
/IMPLIB:filename |
Overrides the default import library name |
/INCLUDE:symbol |
Forces symbol references |
/INCREMENTAL:{YES|NO} |
Controls incremental linking |
Tells the compiler that the application supports addresses larger than two gigabytes. | |
/LIBPATH:path |
Allows the user to override the environmental library path |
Generates import libraries in Visual C++ Version 5.0 format | |
/MACHINE:{IX86|ALPHA|ARM|MIPS|MIPSR41XX|PPC|SH3|SH4} |
Specifies the target platform |
Creates a map file | |
/MAPINFO:{EXPORTS|FIXUPS|LINES} |
Includes the specified information in the map file |
/MERGE:from=to |
Combines sections |
/NODEFAULTLIB[:library] |
Ignores all (or specified) default libraries when resolving external references |
Creates a resource-only DLL | |
Suppresses startup banner | |
/OPT:{REF|NOREF|ICF[,iterations]|NOICF} |
Controls LINK optimizations |
/ORDER:@filename |
Places COMDATs into the image in a predetermined order |
/OUT:filename |
Specifies the output file name |
/PDB:filename |
Creates a program database (.PDB) file |
/PDBTYPE:{con[solidate]|sept[ypes]} |
Specifies where to store the Program Database (PDB) debug type information. |
Enables profiling (creates a mapfile) | |
Sets the checksum in the .EXE header | |
/SECTION:name,attributes |
Overrides the attributes of a section |
/STACK:reserve[,commit] |
Sets the size of the stack in bytes |
/STUB:filename |
Attaches an MS-DOS stub program to a Win32 program |
/SUBSYSTEM:{CONSOLE|WINDOWS|NATIVE|POSIX|WINDOWSCE} [,major[.minor] ] |
Tells the operating system how to run the .EXE file |
/SWAPRUN:{NET|CD} |
Tells the operating system to copy the linker output to a swap file before running it |
/VERBOSE[:LIB] |
Prints linker progress messages |
/VERSION:major[.minor] |
Assigns a version number |
Creates a virtual device driver (VxD) | |
/WARN[:level] |
Specifies warning level |
/WS:AGGRESSIVE |
Aggressively trim process memory |
옵션 |
설명 |
/ALIGN:number |
Specifies the alignment of each section |
/BASE:{address | @filename,key} |
Sets a base address for the program |
/COMMENT:["]comment["] |
Inserts a comment string into header |
Creates debugging information | |
/DEBUGTYPE:CV |
Creates particular formats of debugging information |
/DEF:filename |
Passes a module-definition (.DEF) file to the linker |
/DEFAULTLIB:library |
Searches specified library when resolving external references |
Controls the delayed loading of DLLs | |
Causes the delayed loading of the specified DLL | |
Builds a DLL | |
/DRIVER[:UPONLY] |
Creates a Windows NT kernel mode driver |
/ENTRY:function |
Sets the starting address |
/EXETYPE:DYNAMIC |
Builds a virtual device driver |
Exports a function | |
/FIXED[:NO] |
Creates a program that can be loaded only at its preferred base address |
/FORCE[:{MULTIPLE|UNRESOLVED}] |
Forces link to complete in spite of unresolved or multiply defined symbols |
/GPSIZE:# |
Specifies the size of communal variables for MIPS and Alpha platforms |
/HEAP:reserve[,commit] |
Sets the size of the heap in bytes |
/IMPLIB:filename |
Overrides the default import library name |
/INCLUDE:symbol |
Forces symbol references |
/INCREMENTAL:{YES|NO} |
Controls incremental linking |
Tells the compiler that the application supports addresses larger than two gigabytes. | |
/LIBPATH:path |
Allows the user to override the environmental library path |
Generates import libraries in Visual C++ Version 5.0 format | |
/MACHINE:{IX86|ALPHA|ARM|MIPS|MIPSR41XX|PPC|SH3|SH4} |
Specifies the target platform |
Creates a map file | |
/MAPINFO:{EXPORTS|FIXUPS|LINES} |
Includes the specified information in the map file |
/MERGE:from=to |
Combines sections |
/NODEFAULTLIB[:library] |
Ignores all (or specified) default libraries when resolving external references |
Creates a resource-only DLL | |
Suppresses startup banner | |
/OPT:{REF|NOREF|ICF[,iterations]|NOICF} |
Controls LINK optimizations |
/ORDER:@filename |
Places COMDATs into the image in a predetermined order |
/OUT:filename |
Specifies the output file name |
/PDB:filename |
Creates a program database (.PDB) file |
/PDBTYPE:{con[solidate]|sept[ypes]} |
Specifies where to store the Program Database (PDB) debug type information. |
Enables profiling (creates a mapfile) | |
Sets the checksum in the .EXE header | |
/SECTION:name,attributes |
Overrides the attributes of a section |
/STACK:reserve[,commit] |
Sets the size of the stack in bytes |
/STUB:filename |
Attaches an MS-DOS stub program to a Win32 program |
/SUBSYSTEM:{CONSOLE|WINDOWS|NATIVE|POSIX|WINDOWSCE} [,major[.minor] ] |
Tells the operating system how to run the .EXE file |
/SWAPRUN:{NET|CD} |
Tells the operating system to copy the linker output to a swap file before running it |
/VERBOSE[:LIB] |
Prints linker progress messages |
/VERSION:major[.minor] |
Assigns a version number |
Creates a virtual device driver (VxD) | |
/WARN[:level] |
Specifies warning level |
/WS:AGGRESSIVE |
Aggressively trim process memory |
'소프트웨어 > C/VC++' 카테고리의 다른 글
[STL] 시퀀스 컨테이너 <Vector> (0) | 2012.05.14 |
---|---|
윈속 멀티스레드 서버 (Winsock) (0) | 2012.05.14 |
간단한 C++ 매크로 만들기 (0) | 2010.07.21 |
CString ->int -> CString (0) | 2010.07.21 |
CTreeCtrl 검색하기 (0) | 2009.11.11 |