tkchia / newlib-ia16

Fork of IA-16 port of Newlib -- added small and medium model support
GNU General Public License v2.0
13 stars 4 forks source link

Format specifier %Fp not supported for printf #13

Open ecm-pushbx opened 4 years ago

ecm-pushbx commented 4 years ago

I am porting Map to gcc-ia16 and it uses %Fp format specifiers to format far pointers. Support for this seems to be missing from your printf. Test case:

$ cat test.c
#include <stdio.h>
#include <dos.h>

int main(int argc, char** argv) {
  void __far * ptr = MK_FP( 0x12AB, 0x34CD );
  printf( "Fp-formatted pointer = %Fp\n", ptr);
  return 0;
}
$ ia16-elf-gcc -Os test.c -o test.exe && dosemu -dumb -quiet -K "$PWD" -E test.exe
About to Execute : test.exe
Fp-formatted pointer = Fp

Expected output would be 12AB:34CD here.

tkchia commented 4 years ago

Hello @ecm-pushbx,

Thanks for your report again. Unfortunately this is a feature that is very specific to Borland C, and it actually clashes with C99's --- and even Open Watcom's --- idea of what %F means. (C99 says %F means the same as %f, except for infinity and not-a-number. Watcom also treats %F largely like %f.)

Thank you!

ecm-pushbx commented 4 years ago

So I should change the code to use a format like "%04"PRIX16":%04"PRIX16 I take it?

tkchia commented 4 years ago

Hello @ecm-pushbx,

So I should change the code to use a format like "%04"PRIX16":%04"PRIX16 I take it?

That should work. If you use my libi86 library, you can take advantage of the FP_OFF and FP_SEG macros to extract the offset and segment components of the far pointer.

I will also try to think about a way to properly add support for processing far pointers to printf and friends.

Thank you!