According to ISO C,int* main(void)
is not one of the forms of the startup function main
that an implementation is required to support. So the behavior is not defined by the language standard.
int *main(void)
could work as a documented extension provided by your implementation of C. In this manner, C implementations can support additional ways of writing the startup function.
More probably, the construct is erroneous, and your implementation is simply ignoring the situation; it's just compiling the code and letting the machine instructions do what they may. To understand the actual behavior, you have to understand what is happening at that level.
Quite possibly, the bitwise representation of the returned pointer itself is interpreted as an integer termination status value, which translates to an operating system exit code of 56. (Perhaps some bitfield in the value, such as the lowest 8 bits, is 56). That's assuming that int *
and int
are returned from a function in the same way. They might not be. For instance, in C compilers for the Motorola 68000 series of processors there exists the convention that a pointer is returned via the A0 register, and an integer value in D0. So if an int *
returning function is written to satisfy an external reference to something that is expected to return int
, the caller receives whatever garbage happens to be in D0, while the pointer has gone into A0.
Because the behavior is not defined, there is no requirement for a diagnostic! In the C language, you can even write this:
int main[42] = { 3 };
in some environments that will compile, and link. When executed, the array data ends up used as a machine language function image. A program relying on this trick once (perhaps more than once) appeared in the IOCC: International Obfuscated C Contest.