报错信息:
stdlib.h:70:5: error: expected identifier or '(' before 'int'
int abs (int);
^~~
这个错误是在.c文件开头添加了
#include <stdlib.h>
头文件包含后,编译出现的。
觉得十分奇怪,包含标准库头文件为什么会编译报错呢?
我的头文件包含情况是:
#include "user_data_config.h"
#include "json_deal_with.h"
#include "desktop_scene.h"
#include "cJSON.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <typedef.h>
其中,user_data_config.h 是我自己编写的头文件。
这样的顺序下,编译就会报上面哪个错误。
修改为
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <typedef.h>
#include "user_data_config.h"
#include "json_deal_with.h"
#include "desktop_scene.h"
#include "cJSON.h"
后再编译,竟然不报错了,看来头文件包含也是有顺序要求的,标准库要放在前面,避免自己定义的头文件里引入了内容影响到标准库吧。