今天在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