pintf anomaly

Help
Jim B.
2009-10-15
2013-03-12
  • Jim B.
    Jim B.
    2009-10-15

    I'm having trouble printing a string with printf.  It's printing garbage.
    Here is the string Def:
      

         code char *isp_voltage_names = {"Unused00",  //0
                 "Unused01",  //1
                 "Unused02",  //2
                 "Unused03",  //3
                 "Unused04",  //4
                 "Unused05",  //5
                 "Unused06",  //6
                 "Unused07",  //7
                 "Unused08",  //8
                 "Unused09",  //9
                 "Unused10",  //10
                 "Unused11",  //11
                 "Unused12",  //12
                 "Unused13"};  //13

    Here is the function call that's failing…

            printf_fast("%12s",isp_voltage_names);

    Now if I print out the pointer it doesn't make sense.  So I assign a temp pointer and pass that and it works. as in

          point1=isp_voltage_names;
          printf("%p",isp_voltage_names);  //print pointer.
          printf("%p",point1);  //print the pointer.
          printf("%12s",point1);  //works.

    The output looks like this

        C:0xb63cC:0x8cb6    Unused01
        C:0xbf3cC:0x8cbf    Unused02
        C:0xc83cC:0x8cc8    Unused03
        C:0xd13cC:0x8cd1    Unused04
        C:0xda3cC:0x8cda    Unused05
        C:0xe33cC:0x8ce3    Unused06
        C:0xec3cC:0x8cec    Unused07
        C:0xf53cC:0x8cf5    Unused08
        C:0xfe3cC:0x8cfe    Unused09
        C:0x073cC:0x8d07    Unused10
        C:0x103cC:0x8d10    Unused11
        C:0x193cC:0x8d19    Unused12
        C:0x223cC:0x8d22    Unused13

    I'm using model-large and the device is a NXP P89V664

    Oh..  and if I use `puts(isp_voltagenames)`
    That works too..

    Is this a bug?  Or this this a stack thing?  It seems like the pointer is off a by a byte…

    Thanks,

    Jim

     
  • Maarten Brock
    Maarten Brock
    2009-10-16

    Please post the SDCC version and the declaration of point1. Also try to cast isp_voltagenames to (char*) when calling printf.