용하는 경우가 있는데요, 이것의 의미는 무엇인가요?
A 커널 소스의 아주 일부분에서는 함수를 선언할 때
void zfree __P((void *, void *ptr));
처럼 인자를 __P() 매크로에 넣어둔 것을 볼 수 있습니다. 이 __P() 매크
로의 정의를 살펴보면 include/linux/ppp_defs.h에서
#ifndef __P
#ifdef __STDC__
#define __P(x) x
#else
#define __P(x) ()
#endif
#endif
이 정의에서 __STDC__는 standard C 즉 ANSI C를 말합니다. 컴파일러가
ANSI C로 컴파일을 하는 경우에는 __STDC__가 정의된 상태에서 컴파일이
이루어집니다.
ANSI C 이전의 C에서는 함수를 정의할 때 다음과 같이 했습니다.
int function()
int a, b
{
}
여기서는 함수의 프로토타입 안에 바로 인자를 기록하지 않고, 함수를 부
를 때에도 전달하는 인자가 올바른 타입(type)인지 검사하지 않습니다. 그
러나 ANSI C에서는 함수의 인자를 명확하게 정의를 해야 하고, 함수를 호
출할 때 전달하는 인자가 올바른 타입(type)인지 검사를 합니다. 즉 위의
함수는 다음과 같이 됩니다.
int function(int a, int b)
지금은 당연히 ANSI C를 사용하기 때문에 이렇게 사용하지만, ANSI C 이전
의 컴파일러를 사용하는 곳에서는 이전 버전의 선언방법을 따르는 경우도
있습니다. __P() 매크로는 ANSI C인 경우(즉, __STDC__가 정의된 경우)에
는 전달받을 인자들을 명확히 기록을 하고, 그렇지 않은 경우는 인자를 생
략하도록 합니다. 이는 ANSI C가 아닌 K&R C로 컴파일할 수 있도록 하기
위한 것 같습니다. 지금은 대부분 ANSI C를 지원하므로 굳이 이렇게 할 필
요가 없습니다. 이러한 형태는 일반 C 라이브러리에서도 볼 수 있습니다.
Names the predefined ANSI C and Microsoft C++ implementation macros.
The compiler recognizes predefined ANSI C macros and the Microsoft C++ implementation provides several more. These macros take no arguments and cannot be redefined. Some of the predefined macros listed below are defined with multiple values. See the following tables for more information.
Macro | Description |
---|---|
__DATE__ |
The compilation date of the current source file. The date is a string literal of the form Mmm dd yyyy. The month name Mmm is the same as for dates generated by the library function asctime declared in TIME.H. |
__FILE__ |
The name of the current source file. __FILE__/FC (Full Path of Source Code File in Diagnostics). expands to a string surrounded by double quotation marks. To ensure that the full path to the file is displayed, use You can create your own wide string version of __FILE__ as follows: #include <stdio.h> |
__LINE__ |
The line number in the current source file. The line number is a decimal integer constant. It can be altered with a #line directive. |
__STDC__ |
Indicates full conformance with the ANSI C standard. Defined as the integer constant 1 only if the /Za compiler option is given and you are not compiling C++ code; otherwise is undefined. |
__TIME__ |
The most recent compilation time of the current source file. The time is a string literal of the form hh:mm:ss. |
__TIMESTAMP__ |
The date and time of the last modification of the current source file, expressed as a string literal in the form Ddd Mmm Date hh:mm:ss yyyy, where Ddd is the abbreviated day of the week and Date is an integer from 1 to 31. |
예제
#include <stdio.h>--------------------------------------------------------------------------------
#define __STDC__ 1
int main(void)
{
printf("\n\nCurrently at lin %d",__LINE__);
printf("\n\nThe value of __DATE__ is : ");
printf(__DATE__);
printf("\n\nThe value of __TIME__ is : ");
printf(__TIME__);
printf("\n\nThe value of __LINE__ is %d",__LINE__);
printf("\n\nThe value of __STDC__ is 1 if ANSI compatibility is on");
(__STDC__==1) ? printf("\nANSI on") : printf("\nANSI off");
printf("\n\nThe value of __FILE__ is : ");
printf(__FILE__);
return 0;
}
출력 결과
--------------------------------------------------------------------------------
Currently at lin 6
The value of __DATE__ is : Feb 26 2007
The value of __TIME__ is : 00:38:36
The value of __LINE__ is 14
The value of __STDC__ is 1 if ANSI compatibility is on
ANSI on
The value of __FILE__ is : D:\WinAPI\PrePro\PrePro.c
'기술자료 > C C++' 카테고리의 다른 글
[오락실]cout 으로 양식화된 출력 사용하기 (0) | 2009.08.12 |
---|---|
C/C++Pre-processor(전처리기)이 대해 ... (0) | 2009.08.11 |
const에 애하여............ (1) | 2009.08.11 |
VISUAL C/C++ PROJECT SETTING (1) | 2009.08.11 |
[賢彬] C++ 에서 멤버 함수포인터 사용하기 (1) | 2009.08.10 |
const 에 대해서 알아봅시다.. (1) | 2009.08.07 |
[賢彬][c++]도대체 가상함수는 어디에다 쓰는 것일까?? (1) | 2009.08.07 |
[C++] 연산자 오버로딩 (1) | 2009.08.05 |