简体   繁体   English

是否有一个GCC选项将foo()视为foo(void)?

[英]Is there a GCC option to treat foo() as foo(void)?

I'm creating a compiler for a language that outputs GNU C as intermediate code. 我正在为一种输出GNU C作为中间代码的语言创建编译器。 (yes, I know there's better ways of doing IR, but I'm lazy and I'm going to rewrite it to be self-hosting anyway). (是的,我知道有更好的做IR的方法,但我很懒,而且我会把它重写为自我托管)。

Currently if I make a function with no arguments, my compiler produces 目前,如果我创建一个没有参数的函数,我的编译器会生成

bar foo(){/*Implementation here*/}

Which is not the same as the desired behaviour: 这与期望的行为不同:

bar foo(void){/*Implementation here*/}

However, I'd like GCC to treat the former as the latter (otherwise I have to make a special case in my code). 但是,我希望海湾合作委员会将前者视为后者(否则我必须在我的代码中提出一个特例)。

Is there a flag for GCC to do this? GCC是否有一面旗帜可以做到这一点?

Having searched through the rather voluminous options provided by gcc , I haven't found anything approaching what you want. 在搜索了gcc提供的相当多的选项之后,我没有找到任何接近你想要的东西。

However, if you're going to generate C code, my belief is that it's encumbent on you to generate correct code. 但是,如果你要生成C代码,我相信你有责任生成正确的代码。 The gcc bods know full well the difference between a "zero argument" function and an "indeterminate number of arguments" one. gcc bods完全清楚“零参数”函数和“不确定数量的参数”之间的区别。 So, my suggestion is to bite the bullet and insert that special case into your code. 因此,我的建议是咬紧牙关并将特殊情况插入到您的代码中。

If it's properly structured, you should only have to make the change in one place :-) 如果结构合理,您只需要在一个地方进行更改:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM