From: SourceForge.net <no...@so...> - 2008-01-19 12:57:16
|
Bugs item #1874922, was opened at 2008-01-18 18:55 Message generated for change (Comment added) made by borutr You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1874922&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. >Category: C-Front End >Group: non bugs >Status: Pending >Resolution: Works For Me Priority: 7 Private: No Submitted By: Laszlo BORTEL (bortel) >Assigned to: Borut Ražem (borutr) Summary: explicit typecast is ineffective for unsigned char parameter Initial Comment: The compiler seems to ignore the explicit (unsigned char) typecast when it is applied to the actual parameter of a function with variable arguments. (Explicit (unsigned char) typecast is necessary even for unsigned char type otherwise the compiler would automatically push a two byte integer onto the stack.) The bug for example blocks the use of printf() function with "%bu" format specifier. C:\>sdcc -v SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.7.4 #4972 (Nov 23 2007) (MINGW32) C:\>ver Microsoft Windows XP [Version 5.1.2600] ---------------------------------------------------------------------- >Comment By: Borut Ražem (borutr) Date: 2008-01-19 13:57 Message: Logged In: YES user_id=568035 Originator: NO Hi Laszlo, I think that the behavior is correct: unsigned char is promoted to int. See ISO/IEC 9899 standard, chapter 6.5.2.2 Function calls, item #6: "If the expression that denotes the called function has a type that does not include a prototype, the integer promotions are performed on each argument, and arguments that have type float are promoted to double. These are called the default argument promotions. ..." In item #7 is written: "... The ellipsis notation in a function prototype declarator causes argument type conversion to stop after the last declared parameter. The default argument promotions are performed on trailing arguments. ..." Which exactly explains your case. Borut ---------------------------------------------------------------------- Comment By: Laszlo BORTEL (bortel) Date: 2008-01-19 11:38 Message: Logged In: YES user_id=1063737 Originator: YES I have increased the priority from the default and attached the list file. >From the file it can be seen that the compiler generates absolutely the same code for parameter passing in both cases. Two bytes pushed onto the stack for unsigned char variable: 0008 146 _main: 147 ; BugReport18.c:5: printf ("%u", u);//correct 0008 74 01 148 mov a,#0x01 000A C0 E0 149 push acc 000C E4 150 clr a 000D C0 E0 151 push acc 000F 74r00 152 mov a,#__str_0 0011 C0 E0 153 push acc 0013 74s00 154 mov a,#(__str_0 >> 8) 0015 C0 E0 155 push acc 0017 74 80 156 mov a,#0x80 0019 C0 E0 157 push acc 001B 12s00r00 158 lcall _printf 001E E5 81 159 mov a,sp 0020 24 FB 160 add a,#0xfb 0022 F5 81 161 mov sp,a 162 ; BugReport18.c:6: printf ("%bu", (unsigned char)u);//buggy 0024 74 01 163 mov a,#0x01 0026 C0 E0 164 push acc 0028 E4 165 clr a 0029 C0 E0 166 push acc 002B 74r03 167 mov a,#__str_1 002D C0 E0 168 push acc 002F 74s00 169 mov a,#(__str_1 >> 8) 0031 C0 E0 170 push acc 0033 74 80 171 mov a,#0x80 0035 C0 E0 172 push acc 0037 12s00r00 173 lcall _printf 003A E5 81 174 mov a,sp 003C 24 FB 175 add a,#0xfb 003E F5 81 176 mov sp,a 0040 22 177 ret File Added: BugReport18.lst ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1874922&group_id=599 |