Typically languages need a starting point. In java
, c
, c++
, ada
, pascal
, assembly
, etc, a method or a block (in the case of pascal) is used to know where the application will start. p>
In the code starts in the _start
method (if it is Linux), C decides that the program should start in main
and pascal has a begin
and end.
to tell where the application will start.
The return of the method is to know if everything went well during the execution of your program.
Return usage example:
$ gcc main.c -o compiled
$ echo $?
If the file is compiled successfully it will return 0 , the other values are for different types of errors.
Another method of use is:
$ gcc -fPIC -shared -O2 mylib.c -o libmy.so &&
$ gcc main.c -o compiled ./libmy.so &&
$ echo "compilado com sucesso!" ||
$ echo "Erro ao compilar!"
The &&
symbol refers to a e
condition, if the 2 files were successfully compiled, the first echo
will be called because it is part of the e
condition, otherwise it will be called the second echo
, because the condition or
is only called if the e
is false.