From: SourceForge.net <no...@so...> - 2004-11-13 07:59:25
|
Bugs item #1064087, was opened at 2004-11-10 20:57 Message generated for change (Comment added) made by scdgro77 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1064087&group_id=599 Category: msc51(8051) target Group: non bugs >Status: Open Resolution: Rejected Priority: 5 Submitted By: gerrit (scdgro77) Assigned to: Nobody/Anonymous (nobody) Summary: wrong compilation of adding chars Initial Comment: when i'm compiling the following line it produces wrong output. all vars are chars ! when they are integers, the compiling produces the right output. So it goes wrong with chars ! test = '0' + i2c_read_bytes; compiled with test and i2c_read_bytes as integers : 345 mov r4,_i2c_comm_PARM_3 347 mov a,#0x30 349 add a,r4 350 mov _i2c_comm_test_1_1,a Wrong output with test and i2c_read_bytes as chars : 340 ;i2c.c:61: test = '0' + i2c_read_bytes; 342 mov _i2c_comm_test_1_1,r3 See the file i2c.c for further details Use the file ./compile to compile the stuff Platform is gentoo linux. SDCC -v output : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.4.2 (Oct 24 2004) (UNIX) sc...@ne... ---------------------------------------------------------------------- >Comment By: gerrit (scdgro77) Date: 2004-11-13 08:59 Message: Logged In: YES user_id=1156788 @Epetrich, Sorry i have to critisize you but it seems you haven't done your homework right (and would have closed the bug too soon) The C code remains the same, so in both cases, 1st where i2c_read_bytes is declared as char, 2nd where i2c_read_bytes declared as int, the compiler has to produce code where the '0x30' is added, but it doesn't. In your words, with the char, all is treated as a constant, and with the int, it's treated as a variable. Futhermore, with the int my application works, with the char it doesn't. But please read the answer to maartenbrock also. @Maartenbrock. In 2.4.6 the compiler produces the output as expected, and works with the char. ---------------------------------------------------------------------- Comment By: Erik Petrich (epetrich) Date: 2004-11-13 08:34 Message: Logged In: YES user_id=635249 Although the compiler output may not be what you expected, it appears to be correct to me. The compiler notices that the expression '0' + i2c_read_bytes is constant over the duration of the for loop and so computes the result before the loop begins: mov a,#0x30 add a,_i2x_comm_PARM_3 mov r3,a (lines 314-316 in my copy of i2c.asm; your line numbers do not exactly match with mine, due to version differences I assume). Within the loop, the only thing that remains to do is to assign this result to the variable 'test': mov _i2c_comm_test_1_1,r3 ---------------------------------------------------------------------- Comment By: Maarten Brock (maartenbrock) Date: 2004-11-11 08:51 Message: Logged In: YES user_id=888171 Can you confirm that this still exists in version 2.4.6? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1064087&group_id=599 |