0

I would like to link a program where the main function is not called main. For example:

#include <stdio.h>

int chef()
{
    puts("Bonjour, monde!");
    return 0;
}

How can this be done? For example using some command-line option for gcc when linking to tell it the name of the main function?

If it is possible, then also is there a way to tell it at compile time that a particular named function has the special behavior of main, where the return value defaults to 0 if the end of the function is reached (so that I could equally omit the return statement in this example)?

  • What about `#define chef main`? Of course the prototypes must be compatible with each other. You probably can have the same result at compile time using `-D ` option... – Roberto Caboni Sep 25 '20 at 07:41
  • Thank you. I like the `-D` solution because this will give me also the default return value. Yes the idea is to put this in a compile script so that the code does not need to contain any change. – Faatimah Sep 25 '20 at 07:44
  • ... but the solution shown in the post linked by @mch is better! – Roberto Caboni Sep 25 '20 at 07:44
  • For some reason it is a common misunderstanding that the programmer is allowed to define the form of main(). This is decided by the compiler. It doesn't make sense for the application programmer to rename it. This is a solution looking for a problem that it solves. – Lundin Sep 25 '20 at 07:48
  • Also, in standard C you can always omit `return 0` at the end of main(), as a special case. It's been like that since the year 1999. – Lundin Sep 25 '20 at 07:50

0 Answers0