我对包含文件及其管理方式有以下好奇心GCC:
假设我有一个源文件foo.c和三个头文件foo.h,foo_cfg.h和foo_int.h.
在foo.c中:
#include "foo.h"
#include "foo_int.h"
Run Code Online (Sandbox Code Playgroud)
在foo.h中:
#include "foo_cfg.h"
Run Code Online (Sandbox Code Playgroud)
在foo_cfg.h中:
/* no inclusions */
#define FOO BAR
Run Code Online (Sandbox Code Playgroud)
在foo_int.h中:
/* no inclusions */
#define BAR 0U
Run Code Online (Sandbox Code Playgroud)
我想知道为什么编译成功.foo_cfg.h文件不应该抱怨它不知道BAR符号吗?
此外,我有另一个源文件bar.c,它只包含foo.h文件,仍然有效.
备注:这是我正在处理的一个项目,我正在处理一个复杂的构建环境,其中我没有太多细节.可能是构建环境对此有影响,而不是指定header files?的位置?
可能是这个问题真的很愚蠢,或者我忽略了一些事情,如果是这样我会道歉.
我有两个变量:
unsigned short a,b;
/* When I compare them with a magic number like this */
if (a > 8U) /* all fine*/
/* But when I make the following comparison: */
if ((a-b) > 8U) /* warning: comparison between signed and unsigned*/
/* And when I make the following comparison: */
if ((a-b) > ((unsigned char)8U)) /* all fine again */
Run Code Online (Sandbox Code Playgroud)
你知道为什么我会收到警告吗?这与整数推广有什么关系吗?