本文介绍了C const 的默认类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些 C 代码,并注意到我认为是一个错误,但事实并非如此.我有以下类型声明语句.

I was writing some C code, and noticed what I thought to be an error, but was not. I had the following type declaration statement.

const fee;

然而,它最初没有被捕获,因为编译器和我没有捕获它.所以我很好奇为什么 C 允许这样做以及默认类型是什么.

However, it was uncaught initially because the compiler and I didn't catch it. So I was curious as to why C allows this and what is the default type.

推荐答案

只有原始版本的 C 语言标准 (ANSI/ISO C89/90) 允许这样做.根据隐式int"规则,此类变量声明默认类型为int.该规则从一开始就存在于 C 中.这就是语言最初的定义方式.

Only the original version of C language standard (ANSI/ISO C89/90) allows this. Such variable declaration defaults to type int in accordance with "implicit int" rule. That rule was present in C since the beginning of time. That's just how the language was originally defined.

请注意,声明的 declaration-specifiers 部分不能完全省略,例如只是

Note that the declaration-specifiers portion of a declaration cannot be omitted completely, e.g. a mere

fee;

不声明 int 变量.即使在原始 C 中也是非法的.但是一旦您添加某种声明说明符或限定符,声明就变得合法并默认为 int 类型,如

does not declare an int variable. It is illegal even in the original C. But once you add some sort of declaration specifier or qualifier, the declaration becomes legal and defaults to int type, as in

static fee;
const fee;
register fee;

然而,所有这些在 C99 和更高版本的语言中都是非法的,因为这些版本的语言规范禁止隐式 int".

However, all this is illegal in C99 and in later versions of language, since these versions of language specification outlawed "implicit int".

这篇关于C const 的默认类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 09:49