我在codegolf.stackexchange网站上找到了这个代码。
#include <stdio.h>
#define function int
#define var int
struct { int (*log)(const char *,...); } console = { printf };
/* From here on only JavaScript! */
function fac(x){
if(x < 2) return 1;
return x * fac(x - 1);
}
function main(){
console.log("Hello world!\n");
for(var i = 0; i < 10; i++){
console.log("%i! = %i\n", i, fac(i));
}
return 0;
}
// *Should* we export the main function of this library??/
exports.main = main;
我的问题是,他如何能够在不包含stdarg.h的情况下运行变量函数?
最佳答案
因为他没有操纵。。。参数,但只是将指针传递给一个函数,该函数在内部操作。。。参数,在本例中为printf:
int __cdecl printf(const char *_Format, ...);
注意:并非所有编译器都支持cdecl调用约定。
另外,他定义的宏是没有意义的,在任何情况下都不应该使用,因为它不是C。
关于c - C,可变参数函数和stdarg.h,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22647164/