#1506 printf and code pointers

closed-fixed
nobody
None
5
2009-05-05
2009-02-18
No

The code below was compiled using the latest version of SDCC (SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.8.9 #5
381 (Feb 18 2009) (MSVC)) as

sdcc bug.c

---- bug.c ----

#include <stdio.h>
#include <stdlib.h>
#include <serial_IO.h>

code char * code mystr[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
};

void main (void)
{
unsigned char j;

for(j=0; mystr[j]!=NULL; j++)
printf("mystr[%d]=%s\n", j, mystr[j]);
}

---- bug.c ----

After compiling and loading to micro this was the output obtained:

mystr[0]=
mystr[1]=
mystr[2]=
mystr[3]=
mystr[4]=
mystr[5]=
mystr[6]=

Changing the declaration of mystr from 'code' to 'const'

const char * code mystr[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
};

results in the correct behavior:

mystr[0]=Sun
mystr[1]=Mon
mystr[2]=Tue
mystr[3]=Wed
mystr[4]=Thu
mystr[5]=Fri
mystr[6]=Sat

Discussion

  • Patryk
    Patryk
    2009-03-04

    I think it is the same bug as #2656821: bug in printf. It is fixed now.

     
  • Patryk
    Patryk
    2009-03-04

    I wonder why adding comments to closed bug report is disabled - I would post the same information in bug report #2656821. Also when it happens that cure for the bug is worse than bug itself, there is no better place to post such information than that closed bug report. Such info may be a signal to reopen bug report.

     
  • No, it is a different problem... It is still present after fixing bug #2656821.

     
    • status: open --> closed-fixed
     
  • After fixing bug 2783061 this one is fixed as well.