类型限定符是表达式类型的一部分吗?
Are type qualifiers part of the type of an expression?
在 C 中,
是类型限定符,例如 const
、 volatile
、restrict
和
_Atomic
表达式类型的一部分?
例如
const int x = 3;
x
、const int
或 int
的类型是什么?
- 一个函数的类型是否包括它的类型限定符
参数?
在C标准中有写(6.2.5类型)
26 Any type so far mentioned is an unqualified type. Each unqualified
type has several qualified versions of its type,47) corresponding to
the combinations of one, two, or all three of the const, volatile, and
restrict qualifiers. The qualified or unqualified versions of a type
are distinct types that belong to the same type category and have
the same representation and alignment requirements....
但是根据函数参数,例如这两个声明声明同一个函数
void f( const int );
void f( int );
来自 C 标准(6.7.6.3 函数声明符(包括原型))
- ...(In the determination of type compatibility and of a composite type,
each parameter declared with function or array type is taken as
having the adjusted type and each parameter declared with qualified
type is taken as having the unqualified version of its declared
type.)
这是一个演示程序
#include <stdio.h>
void f( const int );
int main(void)
{
int x = 10;
f( x );
return 0;
}
void f( int x )
{
printf( "The argument is %d\n", x );
}
它的输出是
The argument is 10
请注意,函数的定义可能取决于其参数是使用限定符 const
还是不使用限定符声明的。
在 C 中,
是类型限定符,例如
const
、volatile
、restrict
和_Atomic
表达式类型的一部分?例如
const int x = 3;
x
、const int
或int
的类型是什么?- 一个函数的类型是否包括它的类型限定符 参数?
在C标准中有写(6.2.5类型)
26 Any type so far mentioned is an unqualified type. Each unqualified type has several qualified versions of its type,47) corresponding to the combinations of one, two, or all three of the const, volatile, and restrict qualifiers. The qualified or unqualified versions of a type are distinct types that belong to the same type category and have the same representation and alignment requirements....
但是根据函数参数,例如这两个声明声明同一个函数
void f( const int );
void f( int );
来自 C 标准(6.7.6.3 函数声明符(包括原型))
- ...(In the determination of type compatibility and of a composite type, each parameter declared with function or array type is taken as having the adjusted type and each parameter declared with qualified type is taken as having the unqualified version of its declared type.)
这是一个演示程序
#include <stdio.h>
void f( const int );
int main(void)
{
int x = 10;
f( x );
return 0;
}
void f( int x )
{
printf( "The argument is %d\n", x );
}
它的输出是
The argument is 10
请注意,函数的定义可能取决于其参数是使用限定符 const
还是不使用限定符声明的。