scc

suckless C compiler
git clone git://git.suckless.org/scc
Log | Files | Refs | README | LICENSE

README (3512B)


      1 
      2 Derivations from standard C
      3 ===========================
      4 This compiler is aimed to be being fully compatible with the C99 standard, but
      5 it will have some differences:
      6 
      7 - Type qualifiers are accepted but ignored.
      8   -----------------------------------------
      9 
     10 Type qualifers make the type system ugly, and their uselessness add
     11 unnecessary complexity to the compiler (and increased compilation time):
     12 	- const: The definition of const is not clear in the standard.
     13 	  If a const value is modified the behaviour is undefined
     14 	  behaviour. It seems it was defined in order to be able to
     15 	  allocate variables in ROM rather than error detection. This
     16 	  implememtation will not warn about these modifications and
     17 	  the compiler will treat them like normal variables (the standard
     18 	  specifies that a diagnostic message must be printed).
     19 
     20 	- volatile: This qualifier was added to the standard
     21 	  to be able to deal with longjmp (local variables that are not
     22 	  volatile have undefined state) and for memory mapped registers
     23 	  or variables whose values are modified asynchronously. This can
     24 	  be achieved with special pragma values though.
     25 	  In the first case, it generates a lot of problems with modern
     26 	  processors and multithreading, where not holding the value in a
     27 	  register is not good enough (an explicit memory barrier is needed).
     28 	  In the second case, this is non-portable code by definition
     29 	  (depending on the register mapped), so it is better to deal with
     30 	  it using another solution (compiler extensions or direct
     31 	  assembler).
     32 
     33 	- restrict: This qualifer can only be applied to pointers to
     34 	  mark that the pointed object has no other alias. This qualifer
     35 	  was introduced to be able to fix some performance problems in
     36 	  numerical algorithms, where FORTRAN could achieve a better
     37 	  performance (and in fact even with this specifier FORTRAN has a
     38 	  better performance in this field). Ignoring it doesn't make the
     39 	  compiler non-standard and in almost all applications the performance
     40 	  will be the same.
     41 
     42 - Function type names
     43   -------------------
     44 
     45 C99 allows you to define type names of function types and write something
     46 like:
     47 
     48 int f(int (int));
     49 
     50 Accepting function types in typenames (or abstract declarators) makes the
     51 grammar ambiguous because it is impossible to differentiate between:
     52 
     53         (int (f))  -> function returning int with one parameter of type f
     54         (int (f))  -> integer variable f
     55 
     56 If you don't believe me try this code:
     57 
     58 int
     59 f(int g())
     60 {
     61 	return g();
     62 }
     63 
     64 Function type names are stupid, because they are used as an alias
     65 of the function pointer types, but it is stupid that something
     66 like sizeof(int (int)) is not allowed (because here it should be
     67 understood as the size of a function), but f(int (int)) is allowed
     68 because it is understood as a parameter of function pointer type.
     69 
     70 This complexity is not needed at all as function pointers fix all these
     71 problems without this complexity (and they are the more usual
     72 way of writing such code).
     73 
     74 - Definition of variables with incomplete type
     75   ---------------------------------------------
     76 
     77 C89 allows the definition of variables with incomplete type that
     78 have external linkage and file scope. The type of the variable
     79 is the composition of all the definitions find in the file. The exact
     80 rules are a bit complex (3.7.2), and SCC ignores  them at this moment
     81 and it does not allow any definition of variables with incomplete type.
     82 
     83 If you don't believe me try this code:
     84 
     85 struct foo x;
     86 
     87 struct foo {
     88 	int i;
     89 };