From: jesusc Date: Fri, 6 Jun 2003 18:08:42 +0000 (+0000) Subject: C code is indented in pdf now X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=d42962277734ff07a6d8a4f8bdee7829464e3578;p=fw%2Fsdcc C code is indented in pdf now git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2674 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/doc/sdccman.lyx b/doc/sdccman.lyx index 8b06017f..76d63239 100644 --- a/doc/sdccman.lyx +++ b/doc/sdccman.lyx @@ -3294,13 +3294,10 @@ Make sure the compiler works on a very simple example. ascii \series medium editor: -\series default +\layout Verse -\newline \family typewriter - -\newline char test; \newline @@ -3314,16 +3311,10 @@ void main(void) { test=0; \newline } -\family default - -\newline - -\emph on +\layout Standard -\newline \series medium -\emph default Compile this using the following command: \family sans \series bold @@ -3383,11 +3374,8 @@ standard \series medium header files and libraries. Edit test.c and change it to the following: -\series default - -\newline +\layout Verse -\newline \family typewriter #include @@ -3405,11 +3393,9 @@ void main(void) { strcpy(str1, "testing"); \newline } -\newline +\layout Standard -\newline -\family default \series medium Compile this by typing \family sans @@ -6626,9 +6612,8 @@ default storage class for Small Memory model. Variables declared with this storage class will be allocated in the internal RAM, e.g.: -\newline +\layout Verse -\newline \family typewriter data int iramdata; @@ -6644,9 +6629,8 @@ idata Variables declared with this storage class will be allocated into the indirectly addressable portion of the internal ram of a 8051, e.g.: -\newline +\layout Verse -\newline \family typewriter idata int idi; @@ -6663,9 +6647,8 @@ bit This is a data-type and a storage class specifier. When a variable is declared as a bit, it is allocated into the bit addressable memory of 8051, e.g.: -\newline +\layout Verse -\newline \family typewriter bit iFlag; @@ -6690,9 +6673,8 @@ sfr / sbit \emph default signifies both a data-type and storage class, they are used to describe the special function registers and special bit variables of a 8051, eg: -\newline +\layout Verse -\newline \family typewriter sfr at 0x80 P0; /* special function register P0 at location 0x80 */ @@ -6731,14 +6713,10 @@ SDCC allows (via language extensions) pointers to explicitly point to any \newline Pointer declaration examples: -\newline - -\size small +\layout Verse -\newline \family typewriter -\size default /* pointer physically in xternal ram pointing to object in internal ram */ \newline @@ -6761,14 +6739,8 @@ code unsigned char * code p; /* the folowing is a generic pointer physically located in xdata space */ \newline char * xdata p; -\family default -\size small - -\newline - -\newline +\layout Standard -\size default Well you get the idea. \newline @@ -6877,14 +6849,10 @@ reentrant \emph default keyword in the function declaration, e.g.: -\newline - -\size small +\layout Verse -\newline \family typewriter -\size default unsigned char foo(char i) reentrant \newline { @@ -6893,11 +6861,8 @@ unsigned char foo(char i) reentrant \newline } -\newline - -\family default +\layout Standard -\newline Since stack space on 8051 is limited, the \emph on reentrant @@ -6932,9 +6897,8 @@ Local variables can be assigned storage classes and absolute \end_inset addresses, e.g.: -\newline +\layout Verse -\newline \family typewriter unsigned char foo() { @@ -6965,11 +6929,8 @@ data at 0x31 unsiged char j; \newline } -\newline - -\newline +\layout Standard -\family default In the above example the variable \emph on i @@ -7081,9 +7042,8 @@ tion will NOT be overlayed since these are implemented using external functions, e.g.: -\newline +\layout Verse -\newline \family typewriter #pragma SAVE @@ -7145,11 +7105,8 @@ set_error(10); \newline } -\newline - -\newline +\layout Standard -\family default In the above example the parameter \emph on errcd @@ -7172,9 +7129,8 @@ Interrupt Service Routines SDCC allows interrupt service routines to be coded in C, with some extended keywords. -\newline +\layout Verse -\newline \family typewriter void timer_isr (void) interrupt 2 using 1 @@ -7185,11 +7141,8 @@ void timer_isr (void) interrupt 2 using 1 \newline } -\newline - -\newline +\layout Standard -\family default The number following the \emph on interrupt @@ -7518,14 +7471,10 @@ critical SDCC will generate code to disable all interrupts upon entry to a critical function and enable them back before returning. Note that nesting critical functions may cause unpredictable results. -\newline - -\size small +\layout Verse -\newline \family typewriter -\size default int foo () critical \newline { @@ -7537,11 +7486,8 @@ int foo () critical \newline } -\newline - -\family default +\layout Standard -\newline The critical attribute maybe used with other attributes like \emph on reentrant. @@ -7592,9 +7538,8 @@ return This is particularly useful for interrupt functions, which can have a large (and often unnecessary) prologue/epilogue. For example, compare the code generated by these two functions: -\newline +\layout Verse -\newline \family typewriter data unsigned char counter; @@ -7670,15 +7615,11 @@ _endasm ; \newline } -\family default - -\newline +\layout Standard -\newline For an 8051 target, the generated simpleInterrupt looks like: -\newline +\layout Verse -\newline \family typewriter _simpleIterrupt: @@ -7815,15 +7756,11 @@ acc \SpecialChar ~ \SpecialChar ~ reti -\family default - -\newline +\layout Standard -\newline whereas nakedInterrupt looks like: -\newline +\layout Verse -\newline \family typewriter _nakedInterrupt: @@ -7846,11 +7783,8 @@ reti\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ ; MUST explicitly include ret(i) in _naked function. -\family default - -\newline +\layout Standard -\newline While there is nothing preventing you from writing C code inside a _naked function, there are many ways to shoot yourself in the foot doing this, and it is recommended that you stick to inline assembler. @@ -8304,9 +8238,8 @@ status Collapsed SDCCpeeph.def \emph default carefully before using this option. -\newline +\layout Verse -\newline \family typewriter _asm @@ -8345,14 +8278,8 @@ _endasm \end_inset ; -\family default -\size small - -\newline - -\newline +\layout Standard -\size default The inline assembler code can contain any valid code understood by the assembler , this includes any assembler directives and comment lines. The compiler does not do any validation of the code within the @@ -8372,9 +8299,8 @@ Inline assembler code cannot reference any C-Labels, however it can reference \end_inset defined by the inline assembler, e.g.: -\newline +\layout Verse -\newline \family typewriter foo() { @@ -8448,11 +8374,8 @@ _endasm ; /* some more c code */ \newline } -\newline - -\newline +\layout Standard -\family default In other words inline assembly code can access labels defined in inline assembly within the scope of the funtion. The same goes the other way, ie. @@ -9767,23 +9690,18 @@ Sub-expression Elimination The compiler does local and global common subexpression elimination, e.g.: -\newline +\layout Verse -\newline \family typewriter i = x + y + 1; \newline j = x + y; -\family default - -\newline +\layout Standard -\newline will be translated to -\newline +\layout Verse -\newline \family typewriter iTemp = x + y @@ -9791,30 +9709,22 @@ iTemp = x + y i = iTemp + 1 \newline j = iTemp -\newline - -\family default +\layout Standard -\newline Some subexpressions are not as obvious as the above example, e.g.: -\newline +\layout Verse -\newline \family typewriter a->b[i].c = 10; \newline a->b[i].d = 11; -\family default - -\newline +\layout Standard -\newline In this case the address arithmetic a->b[i] will be computed only once; the equivalent code in C would be. -\newline +\layout Verse -\newline \family typewriter iTemp = a->b[i]; @@ -9822,11 +9732,8 @@ iTemp = a->b[i]; iTemp.c = 10; \newline iTemp.d = 11; -\family default - -\newline +\layout Standard -\newline The compiler will try to keep these temporary variables in registers. \layout Subsubsection @@ -9836,7 +9743,7 @@ Dead-Code Elimination \end_inset -\layout Standard +\layout Verse \family typewriter @@ -9872,15 +9779,11 @@ global = 3;\SpecialChar ~ /* unreachable */ \newline } -\family default - -\newline +\layout Standard -\newline will be changed to -\newline +\layout Verse -\newline \family typewriter int global; void f () @@ -9904,7 +9807,7 @@ Copy-Propagation \end_inset -\layout Standard +\layout Verse \family typewriter @@ -9927,15 +9830,11 @@ j = i; return j; \newline } -\family default - -\newline +\layout Standard -\newline will be changed to -\newline +\layout Verse -\newline \family typewriter int f() { @@ -9957,11 +9856,8 @@ int f() { return 10; \newline } -\newline - -\newline +\layout Standard -\family default Note: the dead stores created by this copy propagation will be eliminated by dead-code elimination. \layout Subsubsection @@ -10015,9 +9911,8 @@ NOINDUCTION \newline Loop Invariant: -\newline +\layout Verse -\newline \family typewriter for (i = 0 ; i < 100 ; i ++) @@ -10025,15 +9920,11 @@ for (i = 0 ; i < 100 ; i ++) \SpecialChar ~ \SpecialChar ~ f += k + l; -\family default - -\newline +\layout Standard -\newline changed to -\newline +\layout Verse -\newline \family typewriter itemp = k + l; @@ -10043,11 +9934,8 @@ for (i = 0; i < 100; i++) \SpecialChar ~ \SpecialChar ~ f += itemp; -\family default - -\newline +\layout Standard -\newline As mentioned previously some loop invariants are not as apparent, all static address computations are also moved out of the loop. \newline @@ -10059,9 +9947,8 @@ Strength Reduction \end_inset , this optimization substitutes an expression by a cheaper expression: -\newline +\layout Verse -\newline \family typewriter for (i=0;i < 100; i++) @@ -10069,15 +9956,11 @@ for (i=0;i < 100; i++) \SpecialChar ~ \SpecialChar ~ ar[i*5] = i*3; -\family default - -\newline +\layout Standard -\newline changed to -\newline +\layout Verse -\newline \family typewriter itemp1 = 0; @@ -10099,11 +9982,8 @@ itemp1 += 5; itemp2 += 3; \newline } -\family default - -\newline +\layout Standard -\newline The more expensive multiplication \begin_inset LatexCommand \index{Multiplication} @@ -10142,8 +10022,8 @@ The 'for' loop is of the form \newline \family typewriter -for ( = ; [< | <=] ; [++ | - += 1]) +for( = ; [< | <=] ; [++ | + += 1]) \newline \SpecialChar ~ \SpecialChar ~ @@ -10188,9 +10068,8 @@ Algebraic Simplifications SDCC does numerous algebraic simplifications, the following is a small sub-set of these optimizations. -\newline +\layout Verse -\newline \family typewriter i = j + 0 ; /* changed to */ i = j; @@ -10200,11 +10079,8 @@ i /= 2; /* changed to */ i >>= 1; i = j - j ; /* changed to */ i = 0; \newline i = j / 1 ; /* changed to */ i = j; -\family default - -\newline +\layout Standard -\newline Note the subexpressions \begin_inset LatexCommand \index{Subexpression} @@ -10233,9 +10109,9 @@ SDCC changes switch statements to jump tables The case labels are in numerical sequence, the labels need not be in order, and the starting number need not be one or zero. -\newline +\begin_deeper +\layout Verse -\newline \family typewriter switch(i) {\SpecialChar ~ @@ -10340,12 +10216,10 @@ case 4: ... \SpecialChar ~ \SpecialChar ~ } -\newline - -\newline +\layout Standard -\family default Both the above switch statements will be implemented using a jump-table. +\end_deeper \layout Itemize The number of case labels is at least three, since it takes two conditional @@ -10360,97 +10234,117 @@ The number of case labels is less than 84, since each label takes 3 bytes Switch statements which have gaps in the numeric sequence or those that have more that 84 case labels can be split into more than one switch statement for efficient code generation, e.g.: -\newline +\layout Verse -\newline \family typewriter switch (i) { \newline +\SpecialChar ~ +\SpecialChar ~ case 1: ... \newline +\SpecialChar ~ +\SpecialChar ~ case 2: ... \newline +\SpecialChar ~ +\SpecialChar ~ case 3: ... \newline +\SpecialChar ~ +\SpecialChar ~ case 4: ... \newline +\SpecialChar ~ +\SpecialChar ~ case 9: ... \newline -case 10: ... +\SpecialChar ~ +\SpecialChar ~ +case 10: ... \newline +\SpecialChar ~ +\SpecialChar ~ case 11: ... \newline +\SpecialChar ~ +\SpecialChar ~ case 12: ... \newline } -\family default - -\newline +\layout Standard -\newline If the above switch statement is broken down into two switch statements -\newline +\layout Verse -\newline \family typewriter switch (i) { \newline +\SpecialChar ~ +\SpecialChar ~ case 1: ... \newline +\SpecialChar ~ +\SpecialChar ~ case 2: ... \newline +\SpecialChar ~ +\SpecialChar ~ case 3: ... \newline +\SpecialChar ~ +\SpecialChar ~ case 4: ... \newline } -\newline - -\newline +\layout Standard -\family default and -\family typewriter +\layout Verse -\newline -\newline +\family typewriter switch (i) { \newline +\SpecialChar ~ +\SpecialChar ~ case 9: \SpecialChar ~ ... \newline +\SpecialChar ~ +\SpecialChar ~ case 10: ... \newline +\SpecialChar ~ +\SpecialChar ~ case 11: ... \newline +\SpecialChar ~ +\SpecialChar ~ case 12:\SpecialChar ~ ... \newline } -\newline - -\newline +\layout Standard -\family default then both the switch statements will be implemented using jump-tables whereas the unmodified switch statement will not be. \layout Subsubsection @@ -10467,11 +10361,10 @@ Bit shifting is one of the most frequently used operation in embedded programmin g. SDCC tries to implement bit-shift operations in the most efficient way possible, e.g.: -\newline +\layout Verse -\family typewriter -\newline +\family typewriter unsigned char i; \newline ... @@ -10480,17 +10373,13 @@ unsigned char i; i>>= 4; \newline ... -\newline - -\family default +\layout Standard -\newline generates the following code: -\newline +\layout Verse -\family typewriter -\newline +\family typewriter mov a,_i \newline swap a @@ -10498,16 +10387,12 @@ swap a anl a,#0x0f \newline mov _i,a -\family default - -\newline +\layout Standard -\newline In general SDCC will never setup a loop if the shift count is known. Another example: -\newline +\layout Verse -\newline \family typewriter unsigned int i; @@ -10518,15 +10403,11 @@ unsigned int i; i >>= 9; \newline ... -\family default - -\newline +\layout Standard -\newline will generate: -\newline +\layout Verse -\newline \family typewriter mov a,(_i + 1) @@ -10538,11 +10419,8 @@ clr c rrc a \newline mov _i,a -\family default - -\newline +\layout Standard -\newline Note that SDCC stores numbers in little-endian format (i.e. lowest order first). \layout Subsubsection @@ -10557,9 +10435,8 @@ Bit-rotation A special case of the bit-shift operation is bit rotation, SDCC recognizes the following expression to be a left bit-rotation: -\newline +\layout Verse -\newline \family typewriter unsigned char i; @@ -10571,14 +10448,14 @@ i = ((i << 1) | (i >> 7)); \family default \newline + +\family typewriter ... -\newline +\layout Standard -\newline will generate the following code: -\newline +\layout Verse -\newline \family typewriter mov a,_i @@ -10586,16 +10463,12 @@ mov a,_i rl a \newline mov _i,a -\family default - -\newline +\layout Standard -\newline SDCC uses pattern matching on the parse tree to determine this operation.Variatio ns of this case will also be recognized as bit-rotation, i.e.: -\newline +\layout Verse -\newline \family typewriter i = ((i >> 7) | (i << 1)); /* left-bit rotation */ @@ -10613,10 +10486,9 @@ It is frequently required to obtain the highest order bit of an integral type (long, int, short or char types). SDCC recognizes the following expression to yield the highest order bit and generates optimized code for it, e.g.: -\newline +\layout Verse + -\newline - \family typewriter unsigned int gint; \newline @@ -10641,20 +10513,13 @@ hob = (gint >> 15) & 1; \newline } -\family default - -\newline +\layout Standard -\newline will generate the following code: -\newline +\layout Verse -\family typewriter -\newline -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ +\family typewriter \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ @@ -10683,9 +10548,7 @@ will generate the following code: 61 ;\SpecialChar ~ hob.c 7 \newline -\SpecialChar ~ -\SpecialChar ~ - 000A E5*01\SpecialChar ~ +000A E5*01\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ @@ -10711,9 +10574,7 @@ will generate the following code: mov\SpecialChar ~ a,(_gint + 1) \newline -\SpecialChar ~ -\SpecialChar ~ - 000C 33\SpecialChar ~ +000C 33\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ @@ -10742,9 +10603,7 @@ will generate the following code: rlc\SpecialChar ~ a \newline -\SpecialChar ~ -\SpecialChar ~ - 000D E4\SpecialChar ~ +000D E4\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ @@ -10773,9 +10632,7 @@ will generate the following code: clr\SpecialChar ~ a \newline -\SpecialChar ~ -\SpecialChar ~ - 000E 13\SpecialChar ~ +000E 13\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ @@ -10804,9 +10661,7 @@ will generate the following code: rrc\SpecialChar ~ a \newline -\SpecialChar ~ -\SpecialChar ~ - 000F F5*02\SpecialChar ~ +000F F5*02\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ @@ -10831,11 +10686,8 @@ will generate the following code: \SpecialChar ~ mov\SpecialChar ~ _foo_hob_1_1,a -\newline - -\newline +\layout Standard -\family default Variations of this case however will \emph on not @@ -10845,17 +10697,13 @@ not way to get the highest order bit, (it is portable). Of course it will be recognized even if it is embedded in other expressions, e.g.: -\newline +\layout Verse -\newline \family typewriter xyz = gint + ((gint >> 15) & 1); -\family default - -\newline +\layout Standard -\newline will still be recognized. \layout Subsubsection @@ -10897,9 +10745,8 @@ status Collapsed \emph default option. The rule language is best illustrated with examples. -\newline +\layout Verse -\newline \family typewriter replace { @@ -10919,69 +10766,46 @@ mov a,%1 mov %1,a \newline } -\family default - -\newline +\layout Standard -\newline The above rule will change the following assembly \begin_inset LatexCommand \index{Assembler routines} \end_inset sequence: -\newline +\layout Verse -\newline \family typewriter -\SpecialChar ~ -\SpecialChar ~ mov r1,a \newline -\SpecialChar ~ -\SpecialChar ~ mov a,r1 -\family default - -\newline +\layout Standard -\newline to -\newline +\layout Verse -\newline \family typewriter mov r1,a -\family default - -\newline +\layout Standard -\newline Note: All occurrences of a \emph on %n \emph default (pattern variable) must denote the same string. With the above rule, the assembly sequence: -\newline +\layout Verse -\newline \family typewriter -\SpecialChar ~ -\SpecialChar ~ mov r1,a \newline -\SpecialChar ~ -\SpecialChar ~ mov a,r2 -\family default - -\newline +\layout Standard -\newline will remain unmodified. \newline @@ -11026,21 +10850,15 @@ ajmp and \family typewriter acall -\family default - -\newline +\layout Verse -\newline \family typewriter replace { lcall %1 } by { acall %1 } \newline replace { ljmp %1 } by { ajmp %1 } -\family default - -\newline +\layout Standard -\newline The \emph on inline-assembler code @@ -11055,9 +10873,8 @@ e is MCU independent. \newline The syntax for a rule is as follows: -\newline +\layout Verse -\newline \family typewriter rule := replace [ restart ] '{' ' @@ -11119,11 +10936,8 @@ n' '}' [if ] ' \backslash n' -\newline - -\family default +\layout Standard -\newline := assembly instruction (each instruction including labels must be on a separate line). \newline @@ -11137,9 +10951,8 @@ The optimizer will apply to the rules one by one from the top in the sequence the same rule again. An example of this (not a good one, it has side effects) is the following rule: -\newline +\layout Verse -\newline \family typewriter replace restart { @@ -11157,90 +10970,56 @@ push %1 } by { ; nop \newline } -\family default - -\newline +\layout Standard -\newline Note that the replace pattern cannot be a blank, but can be a comment line. Without the 'restart' option only the inner most 'pop' 'push' pair would be eliminated, i.e.: -\newline +\layout Verse -\newline \family typewriter -\SpecialChar ~ -\SpecialChar ~ pop ar1 \newline -\SpecialChar ~ -\SpecialChar ~ pop ar2 \newline -\SpecialChar ~ -\SpecialChar ~ push ar2 \newline -\SpecialChar ~ -\SpecialChar ~ push ar1 -\family default - -\newline +\layout Standard -\newline would result in: -\newline +\layout Verse -\newline \family typewriter -\SpecialChar ~ -\SpecialChar ~ pop ar1 \newline -\SpecialChar ~ -\SpecialChar ~ ; nop \newline -\SpecialChar ~ -\SpecialChar ~ push ar1 -\family default - -\newline +\layout Standard -\newline \emph on with \emph default the restart option the rule will be applied again to the resulting code and then all the pop-push pairs will be eliminated to yield: -\newline +\layout Verse -\newline \family typewriter -\SpecialChar ~ -\SpecialChar ~ ; nop \newline -\SpecialChar ~ -\SpecialChar ~ ; nop -\family default - -\newline +\layout Standard -\newline A conditional function can be attached to a rule. Attaching rules are somewhat more involved, let me illustrate this with an example. -\newline +\layout Verse -\newline \family typewriter replace { @@ -11262,11 +11041,8 @@ sjmp %5 %2: \newline } if labelInRange -\family default - -\newline +\layout Standard -\newline The optimizer does a look-up of a function name table defined in function \emph on @@ -11483,9 +11259,8 @@ The pragma's are intended to be used to turn-off certain optimizations which are used to control options & optimizations for a given function; pragmas should be placed before and/or after a function, placing pragma's inside a function body could have unpredictable results. -\newline +\layout Verse -\newline \family typewriter #pragma SAVE @@ -11535,11 +11310,8 @@ int foo () \end_inset /* turn the optimizations back on */ -\family default - -\newline +\layout Standard -\newline The compiler will generate a warning message when extra space is allocated. It is strongly recommended that the SAVE and RESTORE pragma's be used when changing options for a function. @@ -11635,9 +11407,8 @@ Assembler Routine(non-reentrant In the following example the function cfunc calls an assembler routine asm_func, which takes two parameters. -\newline +\layout Verse -\newline \family typewriter extern int asm_func(unsigned char, unsigned char); @@ -11669,15 +11440,11 @@ int main() return c_func(10,9); \newline } -\newline - -\newline +\layout Standard -\family default The corresponding assembler function is: -\newline +\layout Verse -\newline \family typewriter .globl _asm_func_PARM_2 @@ -11780,11 +11547,8 @@ mov dpl \SpecialChar ~ \SpecialChar ~ ret -\newline - -\newline +\layout Standard -\family default Note here that the return values are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for two byte values. 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph',' @@ -11872,9 +11636,8 @@ In this case the second parameter onwards will be passed on the stack, the parameters are pushed from right to left i.e. after the call the left most parameter will be on the top of the stack. Here is an example: -\newline +\layout Verse -\newline \family typewriter extern int asm_func(unsigned char, unsigned char); @@ -11906,15 +11669,11 @@ int main() return c_func(10,9); \newline } -\newline - -\family default +\layout Standard -\newline The corresponding assembler routine is: -\newline +\layout Verse -\newline \family typewriter .globl _asm_func @@ -12016,11 +11775,8 @@ pop _bp \SpecialChar ~ \SpecialChar ~ ret -\newline - -\newline +\layout Standard -\family default The compiling and linking procedure remains the same, however note the extra entry & exit linkage required for the assembler code, _bp is the stack frame pointer and is used to compute the offset into the stack for parameters @@ -12092,11 +11848,11 @@ functions are not always reentrant. structures cannot be assigned values directly, cannot be passed as function parameters or assigned to each other and cannot be a return value from a function, e.g.: -\family typewriter +\begin_deeper +\layout Verse -\newline -\newline +\family typewriter struct s { ... }; \newline @@ -12128,8 +11884,8 @@ s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ \newline } \newline -struct s foo1 (struct s parms) /* is invalid in SDCC although allowed in - ANSI */ +struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI + */ \newline { \newline @@ -12153,6 +11909,7 @@ struct s rets; return rets;/* is invalid in SDCC although allowed in ANSI */ \newline } +\end_deeper \layout Itemize 'long long @@ -12190,11 +11947,11 @@ Old K&R style \end_inset function declarations are NOT allowed. -\newline +\begin_deeper +\layout Verse -\family typewriter -\newline +\family typewriter foo(i,j) /* this old style of function declarations */ \newline int i,j; /* are valid in ANSI but not valid in SDCC */ @@ -12209,14 +11966,15 @@ int i,j; /* are valid in ANSI but not valid in SDCC */ \newline } +\end_deeper \layout Itemize functions declared as pointers must be dereferenced during the call. -\newline +\begin_deeper +\layout Verse -\family typewriter -\newline +\family typewriter int (*foo)(); \newline ... @@ -12225,6 +11983,7 @@ int (*foo)(); /* has to be called like this */ \newline (*foo)(); /* ansi standard allows calls to be made like 'foo()' */ +\end_deeper \layout Subsection Cyclomatic Complexity @@ -12302,53 +12061,61 @@ r should do an explicit cast when integral promotion is required. Reducing the size of division, multiplication & modulus operations can reduce code size substantially. Take the following code for example. -\family typewriter +\begin_deeper +\layout Verse -\newline -\newline +\family typewriter foobar(unsigned int p1, unsigned char ch) \newline { \newline - unsigned char ch1 = p1 % ch ; +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +unsigned char ch1 = p1 % ch ; \newline - .... - +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +.... \newline } -\newline - -\family default +\layout Standard -\newline For the modulus operation the variable ch will be promoted to unsigned int first then the modulus operation will be performed (this will lead to a call to support routine _moduint()), and the result will be casted to a char. If the code is changed to -\newline +\layout Verse -\family typewriter -\newline +\family typewriter foobar(unsigned int p1, unsigned char ch) \newline { \newline - unsigned char ch1 = (unsigned char)p1 % ch ; +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +unsigned char ch1 = (unsigned char)p1 % ch ; \newline - .... - +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +.... \newline } -\newline - -\family default +\layout Standard -\newline It would substantially reduce the code generated (future versions of the - compiler will be smart enough to detect such optimization oppurtunities). + compiler will be smart enough to detect such optimization opportunities). +\end_deeper \layout Subsection Notes on MCS51 memory @@ -15129,9 +14896,8 @@ ICode Example This section shows some details of iCode. The example C code does not do anything useful; it is used as an example to illustrate the intermediate code generated by the compiler. -\newline +\layout Verse -\newline \family typewriter 1.\SpecialChar ~ @@ -15225,11 +14991,8 @@ return sum+mul; \newline 21.\SpecialChar ~ } -\newline - -\newline +\layout Standard -\family default In addition to the operands each iCode contains information about the filename and line it corresponds to in the source file. The first field in the listing should be interpreted as follows: