News for hackers. Stuff that matters.
Re:F() vs. F(void) in C vs. C++ by mkehrt on Sunday May 12, 2019 @10:26PM (#19896002)
int main() { return 0; }

Main takes argc and argv, but it's idiomatic to omit them if unused.

Re:F() vs. F(void) in C vs. C++ by eridius on Monday May 13, 2019 @01:35AM (#19896643)
This is irrelevant; this is the function definition, which means the compiler knows this function takes zero arguments.

It works because with the way the C ABI works on all platforms I'm aware of, extra arguments passed to the function can be completely ignored by the function with no ill effects, so the fact that _start actually invokes main with argc and argv can be ignored by main.

Which is to say, you could also write this as

  int main(void) { return 0; }
and that would work equally as well.
Re:F() vs. F(void) in C vs. C++ by innocenat on Monday May 13, 2019 @04:13AM (#19897129)
Not on stdcall i.e. Win32 API.
Re:F() vs. F(void) in C vs. C++ by eridius on Monday May 13, 2019 @02:25PM (#19902225)
I've never done Windows programming but AFAICT you don't use `int main()` on Win32 anyway, you write something like

  int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR, int)
(where WINAPI is just a macro for __stdcall)

I also found a reference saying you can in fact use `int main()` if you want to, in a GUI subsystem Windows app, by using the Microsoft linker options /subsystem:windows /ENTRY:mainCRTStartup, but in that case you're not writing a stdcall function anymore.

EDIT: I guess I should clarify, my previous comment was talking about cdecl functions, i.e. the default calling convention in C.

Re:F() vs. F(void) in C vs. C++ by Vogtinator on Monday May 13, 2019 @02:54AM (#19896859)
That's a special case though and unrelated to (). Like it's also explicitly allowed to omit a return statement in main altogether, which implies a return 0.
Re:F() vs. F(void) in C vs. C++ by kazinator on Tuesday May 14, 2019 @12:53AM (#19906864)
That was added in C99; previously, "falling off" the end of main without a return statement resulted in an indeterminate termination status. Countless sloppily written C programs had garbage termination statuses because of this, making it impossible for higher level programs (e.g. scripts) to reliably test for successful execution.
Re:F() vs. F(void) in C vs. C++ by shawxe on Sunday May 12, 2019 @10:39PM (#19896060)
Why not just use int main(void)?
Re:F() vs. F(void) in C vs. C++ by mkehrt on Sunday May 12, 2019 @10:47PM (#19896101)
I'm confused. main doesn't take void--it takes two arguments. The f() syntax means that the definition doesn't specify how many arguments the function will be called with, while f(void) means it takes no arguments.
Re:F() vs. F(void) in C vs. C++ by pksadiq on Sunday May 12, 2019 @11:25PM (#19896232)
As per the standard, main() can take no argument [ie, main(void)] or 2 arguments [main (int, char asterisk asterisk) or equivalent] or some implementation defined manner. See 5.1.2.2.1 in C2x working draft[0].

[0] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2346.pdf

Re:F() vs. F(void) in C vs. C++ by tropo on Tuesday May 14, 2019 @08:40PM (#19915318)
Wow, it is painful to see that they still haven't accepted case ranges. They are supported by gcc, clang, and icc. Like so:

case 123 ... 456:

Switching on strings is another thing people have been wanting for half a century. It would seep up many programs, because most programmers don't bother to generate a perfect hash or a carefully-balanced tree of "if".