static const int和static int const有什么区别? [英] What is the difference between static const int and static int const?

查看:123
本文介绍了static const int和static int const有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此 answer 使用的OP中:

static int const var = 5;

在条件编译控件的上下文中.

in the context of a Conditional Compilation Control.

使用static const intstatic int const有区别吗?

例如:

static const int var;

vs.

static int const var;

我不知道在staticconst之间中间暗示类型的技术.有区别吗?

I don´t know the technique to imply the type in the middle between static and const. Is there a difference?

推荐答案

声明说明符的语法在C 2018 6.7 1中给出,它显示存储类说明符(例如static),类型(例如shortdouble),限定符(例如const),函数(inline_Noreturn)和对齐方式可以按任何顺序出现. 6.7节中的任何内容均未赋予说明符出现的顺序任何意义,因此我们可以假定说明符的任何组合都具有相同的含义,而与顺序无关.

The grammar for declaration specifiers is given in C 2018 6.7 1, and it shows that specifiers for storage class (such as static), type (such as short or double), qualifiers (such as const), functions (inline and _Noreturn), and alignment may appear in any order. Nothing in clause 6.7 gives any meaning to the order in which the specifiers appear, so we may presume any combination of specifiers has the same meaning regardless of order.

在这方面,唯一提及顺序"的内容出现在6.7.2 2中,它表示……类型说明符可以以任何顺序出现,并且可能与其他声明说明符混合在一起."因此,您可以为static const long long int编写long static int const long,就像您可以说红色方型大房子"而不是红色方型大房子"一样,虽然没有规则,但是它会

The only mention of "order" in this regard appears in 6.7.2 2, which says "… the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers." So you can write long static int const long for static const long long int, just as you can say "square red big house" instead of "big square red house"—there is no rule against it, but it will seem funny to people and may throw them off.

请注意,指示指针的*以及用于分组或参数列表的()以及用于下标的[]都不是声明说明符,并且不能随意重新排序与声明说明符. (它们实际上是 declarator 的一部分,这是与 declaration-specifiers 分开的声明的一部分.)

Note that the * that indicates a pointer, as well as ( and ) for either grouping or argument lists and [ and ] for subscripts are not declaration specifiers and may not be freely reordered with declaration specifiers. (They are in fact part of a declarator, which is a separate part of a declaration from the declaration-specifiers.)

这篇关于static const int和static int const有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆