You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C99标准中哪一章节规定数组传递给函数时不进行拷贝?

嘿,你找的这个点在C99标准里确实有明确规定,我来给你梳理清楚~

C99中数组函数参数的等价性说明

你观察到的void foo(int array[10]);和void foo(int *array);等价的行为,核心原因是C标准对函数参数里的数组类型做了自动调整,对应的C99标准章节是**6.7.5.3 函数声明符(包括原型)**的第7段,原文是这样的:

A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to type’’, where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation. If the keyword static also appears within the [ and ] of the array type derivation, then for each call to the function, the value of the corresponding actual argument shall provide access to the first element of an array with at least as many elements as specified by the size expression.

简单来说就是:当你在函数参数里写“类型数组”的时候,编译器会自动把它调整成“指向该类型的限定指针”——不管你写的数组大小是10、100,甚至是可变长度数组的[*],最终都会变成指针类型。这就是为什么调用foo时不会把整个数组内容压栈,实际上传递的只是数组首元素的地址。

关于搜索关键词,你之前用的by reference其实不太贴合C的机制(C里没有真正的按引用传递),这个本质是**数组退化为指针(array decay)**在函数参数场景下的标准化表现。你可以试试这些搜索词:

  • array parameter adjustment C99
  • function parameter array decay C standard
  • 直接搜章节号相关的内容,比如C99 6.7.5.3 function declarators

额外补充个小细节:如果参数里加了static(比如void foo(int array[static 10]);),标准会要求实际传入的数组至少有10个元素,但这依然不会改变参数是指针的本质,只是多了一个对传入参数的约束。

内容的提问来源于stack exchange,提问作者nowox

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:25:30