Hacker News new | past | comments | ask | show | jobs | submit login

What's wrong with that?



In C function prototypes with no arguments are strange.

  void g();
Means that g is a function which takes a not-specified number of arguments (but not a variable number of arguments).

Almost always what you want to do is

  void g(void)
Which says that g takes 0 arguments.

Having said that, declaring it as g() should work fine as long as you always provided that you always invoke it with the correct arguments. If you try invoking it with the wrong arguments, then the compiler will let you, and your program may just break in fun and exciting ways.

Edit: looking closer, it looks like the intent might have been to alias f and g. But, as discussed above, it does so in a way that will break horribly if g expects any arguments.


Well, at the risk of stating the obvious: `return expr;` is meant to return whatever expr evaluates to.

Here, g()'s return type is void, so there's no value to return and at the same time, f()'s return type is void, so return should not have an expr to begin with.

This statement is effectively equivalent to: "g(); return;".


> so return should not have an expr to begin with.

Thats one way to think about it. Another is that void is a type - which is obviously true given you can have void* pointers and functions can return void. In this example, f() returns a void expression, so that’s a perfectly fine thing to return from g.


void* is leaps-and-bounds different from void. It is an expression, it has storage, you can actually assign something to it. You can't have a variable of type void; "void var;" is meaningless. A function doesn't "return" void. void simply denotes that a function doesn't return anything.


You can't have a variable of type void, but you can have an expression of type void - calling a function that returns void does just that (in C++, "throw" is also a void-typed expression).


Not the parent but I too don't see what's wrong with that.


so?




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: