X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=doc%2Fcoding.sgml;h=dc07c091a33647b175a6b312ef0c162dc6df41b9;hb=3d9ac21b806b76fb134c53fad5aca83191917c75;hp=f6dfc3a357c891fb15c12af445d2c19d146542b9;hpb=a8d3b83c43e79702a41b0049d65ea51e62dacf09;p=cc65 diff --git a/doc/coding.sgml b/doc/coding.sgml index f6dfc3a35..dc07c091a 100644 --- a/doc/coding.sgml +++ b/doc/coding.sgml @@ -3,7 +3,6 @@
cc65 coding hints <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>2000-12-03, 2009-09-01 <abstract> How to generate the most effective code with cc65. @@ -128,17 +127,17 @@ and predecrement operators if you don't need the resulting value. That means, use <tscreen><verb> - ... - ++i; - ... + ... + ++i; + ... </verb></tscreen> instead of <tscreen><verb> - ... - i++; - ... + ... + i++; + ... </verb></tscreen> @@ -149,24 +148,24 @@ The compiler produces optimized code, if the value of a pointer is a constant. So, to access direct memory locations, use <tscreen><verb> - #define VDC_STATUS 0xD601 - *(char*)VDC_STATUS = 0x01; + #define VDC_STATUS 0xD601 + *(char*)VDC_STATUS = 0x01; </verb></tscreen> That will be translated to <tscreen><verb> - lda #$01 - sta $D601 + lda #$01 + sta $D601 </verb></tscreen> The constant value detection works also for struct pointers and arrays, if the subscript is a constant. So <tscreen><verb> - #define VDC ((unsigned char*)0xD600) - #define STATUS 0x01 - VDC[STATUS] = 0x01; + #define VDC ((unsigned char*)0xD600) + #define STATUS 0x01 + VDC[STATUS] = 0x01; </verb></tscreen> will also work. @@ -183,14 +182,14 @@ Initialization of local variables when declaring them gives shorter and faster code. So, use <tscreen><verb> - int i = 1; + int i = 1; </verb></tscreen> instead of <tscreen><verb> - int i; - i = 1; + int i; + i = 1; </verb></tscreen> But beware: To maximize your savings, don't mix uninitialized and initialized @@ -202,18 +201,18 @@ variables, you force the compiler to allocate space for the uninitialized variables each time, it parses an initialized one. So do this: <tscreen><verb> - int i, j; - int a = 3; - int b = 0; + int i, j; + int a = 3; + int b = 0; </verb></tscreen> instead of <tscreen><verb> - int i; - int a = 3; - int j; - int b = 0; + int i; + int a = 3; + int j; + int b = 0; </verb></tscreen> The latter will work, but will create larger and slower code. @@ -229,17 +228,17 @@ common cases. Don't use <tscreen><verb> - char* a; - char b, c; - char b = *(a + c); + char* a; + char b, c; + char b = *(a + c); </verb></tscreen> Use <tscreen><verb> - char* a; - char b, c; - char b = a[c]; + char* a; + char b, c; + char b = a[c]; </verb></tscreen> instead.