小编Mir*_*ica的帖子

在C好奇心中包含头文件

我对包含文件及其管理方式有以下好奇心GCC:

假设我有一个源文件foo.c和三个头文件foo.h,foo_cfg.hfoo_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?的位置?

可能是这个问题真的很愚蠢,或者我忽略了一些事情,如果是这样我会道歉.

c header

3
推荐指数
1
解决办法
206
查看次数

签名和未签名警告之间的比较

我有两个变量:

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)

你知道为什么我会收到警告吗?这与整数推广有什么关系吗?

c

0
推荐指数
1
解决办法
2523
查看次数

标签 统计

c ×2

header ×1