gpt4 book ai didi

c - 类型限定符是表达式类型的一部分吗?

转载 作者:太空狗 更新时间:2023-10-29 16:55:18 25 4
gpt4 key购买 nike

在 C 中,

  1. 是类型限定符,例如 constvolatilerestrict_Atomic 表达式类型的一部分?

    例如

    const int x = 3;

    xconst int还是int的类型?

  2. 函数的类型是否包括它的类型限定符参数?

最佳答案

在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 函数声明符(包括原型(prototype)))

  1. ...(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 - 类型限定符是表达式类型的一部分吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45743106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com