scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

README (4668B)


      1 Compiling
      2 =========
      3 
      4 SCC is a portable toolchain that can be compiled on any UNIX system
      5 out of the box. It supports three main configuration options that
      6 can be passed to the command line:
      7 
      8 	- CROSS_COMPILE:
      9           Specify a prefix name for the tools called by the Makefile.
     10 
     11 	- CONF: Specify which version of libc to build.
     12 	  Once the build process completes only the target specified in
     13           CONF will be built. Supported values are:
     14 
     15 		- amd64-linux (default)
     16 		- amd64-darwin
     17 		- amd64-openbsd
     18 		- arm64-linux
     19 		- amd64-dragonfly
     20 		- amd64-netbsd
     21 		- arm32-linux
     22 
     23 	- TOOL: Specify the toolchain type to be used.  Possible
     24 	  supported values are:
     25 
     26 		- unix (by default)
     27 		- gnu
     28 		- gnu-darwin
     29 		- clang
     30 
     31 Deviations from standard C
     32 ===========================
     33 This compiler aims to be fully compatible with the C99 standard, but
     34 it will have some differences:
     35 
     36 - Type qualifiers are accepted but ignored.
     37   -----------------------------------------
     38 
     39 Type qualifiers make the type system ugly, and their uselessness adds
     40 unnecessary complexity to the compiler (and increased compilation time):
     41 
     42 	- const: The definition of const is not clear in the standard.
     43 	  If a const value is modified the behavior is undefined
     44 	  behaviour. It seems it was defined in order to be able to
     45 	  allocate variables in ROM rather than error detection. This
     46 	  implememtation will not warn about these modifications and
     47 	  the compiler will treat them like normal variables (the standard
     48 	  specifies that a diagnostic message must be printed).
     49 
     50 	- volatile: This qualifier was added to the standard
     51 	  to be able to deal with longjmp (local variables that are not
     52 	  volatile have undefined state) and for memory mapped registers
     53 	  or variables whose values are modified asynchronously. This can
     54 	  be achieved by using special pragma values though.
     55 	  In the first case, it generates a lot of problems with modern
     56 	  processors and multithreading, when not holding the value in a
     57 	  register is not good enough (an explicit memory barrier is needed).
     58 	  In the second case, this is non-portable code by definition
     59 	  (depending on the register mapped), so it is better to deal with
     60 	  it using another solution (compiler extensions or direct
     61 	  assembly). Since it is needed for the correct behaviour
     62 	  of portable programs that use longjmp, this specifier eventually
     63 	  will be implemented.
     64 
     65 	- restrict: This qualifier can only be applied to pointers that
     66 	  mark the pointed object and has no other alias. This qualifier
     67 	  was introduced to be able to fix some performance problems in
     68 	  numerical algorithms, where FORTRAN could achieve a better
     69 	  performance (and in fact even with this specifier FORTRAN has a
     70 	  better performance in this field). Ignoring it doesn't make the
     71 	  compiler non-standard and in almost all applications the performance
     72 	  will be the same.
     73 
     74 - Function type names
     75   -------------------
     76 
     77 C99 allows you to define type names of function types and write something
     78 like:
     79 
     80 int f(int (int));
     81 
     82 Accepting function types in type names (or abstract declarators) makes the
     83 grammar ambiguous because it is impossible to differentiate between:
     84 
     85         (int (f))  -> function returning int with one parameter of type f
     86         (int (f))  -> integer variable f
     87 
     88 If you don't believe me try this code:
     89 
     90 int
     91 f(int g())
     92 {
     93 	return g();
     94 }
     95 
     96 Function type names are stupid, because they are used as an alias
     97 of the function pointer types, but it is stupid that something
     98 like sizeof(int (int)) is not allowed (because here it should be
     99 understood as the size of a function), but f(int (int)) is allowed
    100 because it is understood as a parameter of function pointer type.
    101 
    102 This complexity is not needed at all as function pointers fix all these
    103 problems without this complexity (and they are the more common
    104 way of writing such code).
    105 
    106 - Definition of variables with incomplete type
    107   ---------------------------------------------
    108 
    109 C89 allows the definition of variables with incomplete type that
    110 have external linkage and file scope. The type of the variable
    111 is the composition of all the definitions found in the file. The exact
    112 rules are a bit complex (3.7.2) so SCC ignores them at this moment
    113 by simply not allowing any definition of variables with incomplete type.
    114 
    115 If you don't believe me try this code:
    116 
    117 struct foo x;
    118 
    119 struct foo {
    120 	int i;
    121 };
    122 
    123 - Variadic function alike macros
    124   ------------------------------
    125 
    126 The standard (C99 6.10.3 c 4) forces passing more parameters than
    127 the number of parameters present in the variadic argument list
    128 (excluding ...). SCC accepts a parameter list with the same number
    129 of arguments.
    130 
    131 #define P(a, ...) a
    132 
    133 P(1)