Pregunta

I'm creating a compiler for a language that outputs GNU C as intermediate code. (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).

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?

¿Fue útil?

Solución

Having searched through the rather voluminous options provided by gcc, I haven't found anything approaching what you want.

However, if you're going to generate C code, my belief is that it's encumbent on you to generate correct code. The gcc bods know full well the difference between a "zero argument" function and an "indeterminate number of arguments" one. 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 :-)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top