사전 프로세서 정보 - 1

1550 단어
우리는 C 프로그램을 작성할 때 종종 프로세서와 접촉한다.
예를 들어 아래의 화씨 회전 프로그램
/*
 * celsius.c
 *
 *  Created on: 2012-11-14
 *      Author: xiaobin
 */

#include <stdio.h>

#define FREEZING_PT (16.0 *	\
				2)
#define SCALE_FACTOR (5.0 / 9.0)

int main(void)
{
	float fahrenheit, celsius;
	printf("Enter Fahrenheit temperature: ");
	scanf("%g", &fahrenheit);
	printf("%g
", fahrenheit); celsius = (fahrenheit - FREEZING_PT) * SCALE_FACTOR; printf("Celsius equivalent is: %g", celsius); return 0; }
    1. 사전 프로세서 줄 바꿈
명령은 계속해야 한다는 명확한 지시가 없으면 항상 첫 번째 줄 바꾸기에서 끝난다.다음 줄에서 명령을 계속하려면 현재 줄의 끝에\문자를 사용해야 합니다.
        
#define FREEZING_PT 16.0 *	\
				2
    2. 목록의 괄호 바꾸기
가능한 한 작은 괄호를 사용하여 교체 목록을 묶어라, 이렇게 하면 읽기에 편리하다
    3. 매개변수가 있는 사전 처리
상술한 프로그램은 프로그램의 처리 문장을 대체하기 위해 파라미터를 가진 사전 처리를 사용할 수 있다
#define FA2CE(f) ((f - FREEZING_PT) * SCALE_FACTOR)

첨부: 프로세서 프로그램 포함
/*
 * celsius.c
 *
 *  Created on: 2012-11-14
 *      Author: xiaobin
 */

#include <stdio.h>

#define FREEZING_PT (16.0 *	\
				2)
#define SCALE_FACTOR (5.0 / 9.0)
#define FA2CE(f) ((f - FREEZING_PT) * SCALE_FACTOR)

int main(void)
{
	float fahrenheit, celsius;
	printf("Enter Fahrenheit temperature: ");
	scanf("%g", &fahrenheit);
	printf("%g
", fahrenheit); celsius = FA2CE(fahrenheit); printf("Celsius equivalent is: %g", celsius); return 0; }

좋은 웹페이지 즐겨찾기