top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C: How to compile the code if my file is not having main function?

+2 votes
678 views
C: How to compile the code if my file is not having main function?
posted Nov 27, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
#include<stdio.h>
_start()
{
  printf("hello world\n");
}

while compiling;
cc main.c -nostartfiles

answer Nov 28, 2014 by Chirag Gangdev
Hi Chirag,
This code would crash unless you use an exit(0) at the end.

0 / EXIT_SUCCESS are the values specified by the standard to indicate successful termination.

I am not sure exactly why a crash is observed. But if you use an exit(0), the program terminates normally.

Can anyone shed some light on as to why a crash is observed in the absence of exit(0) in this code?
Ok.... Thankx
Similar Questions
+2 votes

We have a big bunch of C and C++ code in our product and compile main with g++, because I read in

http://www.parashift.com/c++-faq/overview-mixing-langs.html

that this is needed.

Can we get rid of this condition? For example by not using exceptions, which are not caught and not using global/static non pod variables and not using class wide non pod variables?

I tried to find answers to that, but didn't find anything. Most people don't seem to be aware of that "compile main with c++-compiler" rule. If I missed some resource, please excuse.

+1 vote

I know the basic definition of re-entrant code and but don't known when it is really required ?

...