#1631 function "forgets" to return value

z80 port (188)

The following function f "forgets" to return value
stored in tmp. Fault happens with alternatives A and B,
but not with C and D.

// ============================================================
char* fp;

char* f(int n){
char* tmp=fp;
fp+=n; // <--- alternative A: does not work (forgets to return value, view .asm file)
//fp+=3; // <--- alternative B: does not work (forgets to return value, view .asm file)
//fp=(char*) ( ((int)fp) + n ) ; // <--- alternative C: with casts works
//fp++; fp++; fp++; // <--- alternative D: works
return tmp;
// ============================================================

My sdcc -v:

SDCC : mcs51/gbz80/z80/ds390/pic16/pic14/TININative/ds400/hc08 2.9.7 #5756 (Mar 28 2010) (Linux)

My own compilation command (I tried to disable all optimizations):

sdcc --nooverlay --nogcse --nolabelopt --noinvariant --noinduction --nojtbound --noloopreverse --no-peep --no-reg-params --data-loc 0xC000 --code-loc 0x8020 -mz80 -omain.ihx main.c

I include the main.c file for a straight test, and the
.asm files generated by the four alternatives A/B/C/D
for an easy comparison.

Best regards,



  • Andrea Rossetti

    Andrea Rossetti - 2010-04-05

    main.c and four .asm files (one per alternative)

  • Philipp Klaus Krause

    • assigned_to: nobody --> spth
    • status: open --> closed-fixed
  • Philipp Klaus Krause

    Fixed in revision #5786.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks