I’ve a C program as follows:
#include<stdio.h>
void main()
{
printf("Hello");
}
Filename is linkedlist.c
and makefile in the same directory as follows
build: linkedlist.c
gcc -Wall -g -pedantic linkedlist.c -o linkedlist
run:
./linkedlist
I first do M-x compile and then make build followed by M-x compile ->make run which gives output as follows:
-*- mode: compilation; default-directory: "/home/amey/test/" -*-
Compilation started at Sat Sep 22 16:59:13
make run
./linkedlist
Hello make: *** [run] Error 5
Compilation exited abnormally with code 2 at Sat Sep 22 16:59:13
The file generated when ran as ./ gives no error. Can somebody explain what is happening?
Since your main does not return a value or call exit, you are getting a random return code … in this case, 5 (which happens, not entirely coincidentally, to be the length of “Hello” and the value returned by printf). Since it isn’t 0, make interprets it as an error.
To be a conforming C program in a hosted environment, your main must be declared
int, and the end of the function much not be reached (without a return statement). The interpretation of the return value is up to the implementation, but usually 0 is considered success and non-0 is considered an error.