C函数中的变量参数 [英] Variable arguments in C functions

查看:134
本文介绍了C函数中的变量参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关变量参数函数"int func(int, ...)"的信息. 这些函数的参数在哪里分配(堆栈或堆)?

I've read about variable arguments functions "int func(int, ...)". Where do the arguments of these functions get allocated (stack or heap)?

因为我读到va_end()宏释放了分配给va_list的空间,所以"frees"一词引起了我的注意.

Because I read that the va_end() macro frees space assigned to va_list, so that word "frees" caught my eyes.

注意:我知道常规函数会进入堆栈,但是这种类型的函数很有趣,因为参数的数量未知.

Note: I know that regular functions go to stack, but this type of function is interesting as the number of arguments is not known.

我只想确定这不像没有预定义空间的数组; 我们在最后使用malloc()free().

I just want to know for sure that it's not like arrays with no pre-defined space; we use malloc() and free() at the end.

链接: https://www.tutorialspoint.com/cprogramming/c_variable_arguments.htm

推荐答案

本身未指定堆"或堆栈"之类的内容,因此对标准和可移植的

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆