c - “shall be a pointer to the initial element of an array of character type” 在 C99 7.19/C11 7.21 中是什么意思?

标签 c pointers printf language-lawyer c11

最近的 C 标准为 printf("%s",p) 指定:

If no l length modifier is present, the argument shall be a pointer to the initial element of an array of character type

这是否意味着 p 必须与 char * 兼容,或者应该以更宽松的方式解释这句话?该标准的其他部分是否阐明了此处“字符类型数组”的确切含义?

为什么这很重要:如果该短语被严格解释为意味着 p 必须与 char * 兼容,那么一个重要的结果是无符号字符 *p; ... printf("%s", p);char 已签名且 const char *p; 的编译平台上未定义; … printf("%s", p); 未定义。

最佳答案

The three types char, signed char, and unsigned char are collectively called the character types. ...
C11 6.2.5 15

所以“字符类型”数组将包含这 3 个。

constvolatilerestrict 是各种类型的限定符,属于同一类型类别。它们也适用。

Any type so far mentioned is an unqualified type. Each unqualified type has several qualified versions of its type, 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. A derived type is not qualified by the qualifiers (if any) of the type from which it is derived.
C11 6.2.5 26

关于c - “shall be a pointer to the initial element of an array of character type” 在 C99 7.19/C11 7.21 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18788489/

相关文章:

php - 如何使用 php sprintf append 正值 "+"但忽略空值

c - 分段故障处理

c - c中的双分号是什么意思?

html - 使用 C 解析 html

c++ - 标准文本文件是否以 NULL 结尾?

c - 使用整数归档数组的范围问题

c - fork 中的 printf 错误

iOS用printf调试真机

python - 将 python gui 应用程序与 c 控制台应用程序集成的最简单方法

c - C语言数组遍历器