在存储类和类型奇怪GCC警告 [英] Strange GCC warning on storage class and type
问题描述
我有一个头文件,看起来像
header.h
INT TOS;
此文件被包括只有一个code文件
code.C
的#includeheader.h
TOS = 0;
在编译code.C GCC发出警告
code.C:3:1:警告:数据定义没有类型或存储类[默认启用]
code.C:3:1:警告:类型默认为'诠释'在'条款'[默认启用]
我不明白这个警告的原因。是不是等于宣告:在code.C定义TOS?即。
code.C
INT TOS;
TOS = 0;
这是因为你定义 TOS
在全球范围内,这就需要你定义的类型 TOS
(它是一个声明),如果没有类型被设定,默认情况下它是 INT
。
这将导致冲突的错误类型
,
字符X;
X = 0;
I have a header file that looks like
header.h
int TOS;
This file is being included by just one code file
code.c
#include "header.h"
TOS=0;
When compiling code.c GCC issues a warning
code.c:3:1: warning: data definition has no type or storage class [enabled by default] code.c:3:1: warning: type defaults to ‘int’ in declaration of ‘TOS’ [enabled by default]
I fail to understand the cause of this warning. Isn't it equivalent to declaring and defining TOS in code.c? i.e.
code.c
int TOS;
TOS=0;
It is because you define TOS
in the global scope, which need you to define the type of TOS
(it is an declaration), if no type was given, by default it is int
.
This will cause an conflicting type error
,
char x;
x = 0;
这篇关于在存储类和类型奇怪GCC警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!