# Why does gcc compile this (joke) code, but not clang?



## caesius (Nov 16, 2011)

http://robert.martin-legene.dk/files/impossible.c

It's pretty amazing. But I'm curious why I can compile this fine with gcc, but when I try with clang:


```
clang -std=c99 -o impossible impossible.c
```

I've tried every language standard I know of but it won't compile! What gives?

Here's the errors with -std=gnu99 (although it doesn't seem to make a difference which -std is used)


```
impossible.c:16:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main(t,_,a)
^~~~
impossible.c:16:1: error: second parameter of 'main' (argument array) must be of type 'char **'                     
impossible.c:16:1: error: third parameter of 'main' (environment) must be of type 'char **'
impossible.c:75:6: error: expected ':'
,a+1);}
     ^
     :                                                                                                              
impossible.c:24:4: note: to match this '?'                                                                          
t<3?
   ^
impossible.c:75:6: error: expected expression                                                                       
,a+1);}
     ^
impossible.c:75:6: error: expected ':'                                                                              
,a+1);}
     ^
     :                                                                                                              
impossible.c:23:4: note: to match this '?'                                                                          
0<t?
   ^
impossible.c:75:6: error: expected expression                                                                       
,a+1);}
     ^
1 warning and 6 errors generated.
```


----------



## expl (Nov 16, 2011)

Both of these errors are C standard in-depended.

Main function's implementation is not covered by the C standard but rather by general POSIX.1 standard. The standard basically tells that main function has to be either main(int, char **) or main(int, char **, char **) and that compiler should accept both, it's up to compiler to decide what to do in other situations (in this case main(int, int, int) ).

Second error is regarding ternary condition operator nesting. I think C95/C99 say that you have to use parentheses or behavior of the operator order is undefined (up to compiler).


----------



## caesius (Nov 17, 2011)

Thanks for the insight expl, but I still don't understand why gcc will compile this code but clang will not?

Cheers.


----------



## mix_room (Nov 17, 2011)

gcc probably doesn't care about the standards. 

Are you using gcc with the -Wall switch, or without? I think that gcc is quite forgiving if you start it without any parameters, as long as it compiles, it doesn't care about errors.


----------



## fonz (Nov 17, 2011)

mix_room said:
			
		

> gcc probably doesn't care about the standards.


Gcc is more than a compiler, it's actually a C(++) dialect on its own.

Fonz (whether or not this is a good thing is left as an exam question for the reader)


----------

