PCH 警告:标头停止点不能位于宏或#if块中

时间:2023-03-10 06:34:14
PCH 警告:标头停止点不能位于宏或#if块中

今天在vs2010写了点代码,居然报了“PCH 警告:标头停止点不能位于宏或#if块中”。

/*********************
* *
* 文件夹: ▲01 绪论 *
* *
* 文件名: Scanf.c *
* *
*********************/
#ifndef SCANF_C
#define SCANF_C #include <stdio.h>
#include <string.h>
#include <stdarg.h> //提供宏va_list、va_start、va_arg、va_end
#include <ctype.h> //提供isprint原型
..... #endif

原因:vs2010的智能感知要求.h必须以非#if系列的预编译指令打头

修改办法 两种,在代码顶部加上下面一句代码就ok了

#pragma once

修改后的代码

/*********************
* *
* 文件夹: ▲01 绪论 *
* *
* 文件名: Scanf.c *
* *
*********************/
#pragma once
#ifndef SCANF_C
#define SCANF_C #include <stdio.h>
#include <string.h>
#include <stdarg.h> //提供宏va_list、va_start、va_arg、va_end
#include <ctype.h> //提供isprint原型 int Scanf(FILE *fp, char *format, ...)
{
int *i;
char *ch, *s;
float *f;
int count, k, len, n;
int tmp;
va_list ap;
...... #endif

将所有含有#include <***.h> 的头文件放在#ifndef等外,即上方。

//#pragma once
#include <stdio.h>
#include <string.h>
#include <stdarg.h> //提供宏va_list、va_start、va_arg、va_end
#include <ctype.h> //提供isprint原型
#ifndef SCANF_C
#define SCANF_C