I think I found where %p values are formatted in the SDCC source, in printf_large.c line 658:
https://sourceforge.net/p/sdcc/code/HEAD/tree/trunk/sdcc/device/lib/printf_large.c#l658

Is this the right code?

For all platforms other than DS390 and MCS51, which have their own code branches, the code appears to output the second byte first. This will indeed only produce correct pointer formatting for little-endian platforms.

It's only a small detail, and arguably not strictly 'wrong' for big-endian platforms because %p formatting is (as far as I could determine) "implementation defined", but I think this should be fixed. Shall I create a feature request? Or a bug report?

Regards,
Basil Hussain


On 10/11/2021 22:38, Basil Hussain wrote:
Hi all,

Quick question: was the SDCC standard library printf() implementation for the %p conversion specifier written only with little-endian platforms (e.g. 8051) in mind?

I ask because I encounter once again today an annoyance I've encountered before when working on big-endian target platforms such as the STM8. Whenever you use %p, the pointer value is formatted with the bytes in the wrong order. For example, a pointer with value of 0x87A1 is output as "0xa187". It's annoying to have to mentally transpose the bytes when looking at debugging output.

Regards,
Basil Hussain


_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user



_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to