0

I am confused regarding with the c compilers. as per my knowledge for a programmer the code is not important but the internal behaviour is very important.cause if we know how the compiler behaves for the perticular code then we can write programs easily. but i love linux alot. and my system is linux platform i didn't used windows till now because i hate windows os. i don't know how the behaviour regarding turbo C.

in my linux system i have gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) .but i studied in one Website that we should not use main() directly we should use int main() like that. but my compiler that is compiling below code without error.

#include <stdio.h>

main() { /* ... */ }

I am going to attend for the job interviews so which compiler i have to follow suggest me?. i am confused understanding C language. And i want to know based on which compiler the linux kernel written?

2
  • 1
    I would say gcc. With -Wall -pedantic
    – Melon
    Nov 30, 2014 at 10:53
  • 1
    Linux is compiled using GCC (at least the C parts of it)
    – s3lph
    Nov 30, 2014 at 11:00

1 Answer 1

1
$ gcc -Wall -pedantic -o hw hw-no-return.c 
hw-no-return.c:1:1: warning: C++ style comments are not allowed in ISO C90 [enabled by default]
 // 'Hello World!' program 
 ^
hw-no-return.c:1:1: warning: (this will be reported only once per input file) [enabled by default]
hw-no-return.c:5:1: warning: return type defaults to ‘int’ [-Wreturn-type]
 main()
 ^
hw-no-return.c: In function ‘main’:
hw-no-return.c:9:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
$ cat hw-no-return.c 
// 'Hello World!' program 

#include <stdio.h>

main()
{
  printf("Hello World!\n");

}

$ gcc -o hw hw-no-return.c 
$ ./hw
Hello World!
$ 
4
  • That means to know the exact behaviour i have to use like above am i right?
    – ashok
    Nov 30, 2014 at 11:13
  • To know the exact behaviour you would need to analyse the assembly code. If you really need to know, then you should study the language specification. Also, changing the optimization can change a lot. Not to mention that there are as many behaviours as many compilers out there.
    – Melon
    Nov 30, 2014 at 11:29
  • The exact behaviour is dependent om many factors, e.g. gcc is used for many and diverse tasks. There are options that help in most situations. If you know your way around you may write code for almost any processor, strip out the startup module (c.o) and run the code on the bare OS and other similar "hacks". The above creates an 8KB executable, the major portion of that is c.o - somewhere I have the remnants of a test to create real tiny executable (file) - a 'hello world'; less than 100 bytes (that was with gcc on the Amiga).
    – Hannu
    Nov 30, 2014 at 11:43
  • I say c.o above, but you also have printf() linked in from the standard library.
    – Hannu
    Nov 30, 2014 at 11:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .