我遇到过一些我认为已损坏的代码,但由于某些我无法理解或无法找到解释的原因而起作用。如果有人能让我直截了当,我将不胜感激。它在以下代码片段中进行了演示:
#include <stdio.h>
typedef char char_block[16];
void f(char_block *b) {
printf("block 0x%p - b\n", b);
printf("block 0x%p - *b\n", *b);
}
main() {
char_block b = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
f(&b);
}
使用 g+ 编译并执行,打印:
block 0x0x7fff4794b4e0 - b
block 0x0x7fff4794b4e0 - *b
我曾天真地以为
A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to type’’
意味着该函数等同于
void f(char ** b)
但是这里发生了其他事情?
最佳答案
char_block *
是 char (*)[16]
。
关于c - Typedef 数组怪异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38436048/