printf: add support for C23 'b' format, controlled by a flag.

A new label is added in the library named ~C23ORLATER. Its presence in the executable acts as a flag for enabling C23 library behavior, including the new 'b' format. The compiler will generate a reference to it when compiling a program in C23 mode, causing it to be linked in. This can then be detected in library code by including a soft (weak) reference to it, which will be non-zero if the flag is linked in (C23+) or zero if it is not (pre-C23).
This commit is contained in:
Stephen Heumann committed 2026-03-04 19:25:50 -06:00
1 parent 07408538e0
commit 696c2eabf7
2 files changed
+31

No files matched your search

+21
View File
@@ -16,6 +16,27 @@ CC start dummy routine
end
****************************************************************
*
* ~C23orLater - Flag indicating use of C23 or later standards
*
* Notes:
* If a program is compiled in C23 mode (or later),
* ORCA/C will include a reference to ~C23orLater in its
* object code, causing this segment to be linked in.
* Library code should include only soft references to it.
* "lda #~C23orLater(soft reference)" will give 0 for
* pre-C23 modes, or nonzero for C23+, so library code
* can detect the language mode and behave accordingly.
*
****************************************************************
*
~C23Flag start
ds 1 padding to ensure ~C23orLater ...
~C23orLater entry
ds 1 ... is not at start of a bank
end
****************************************************************
*
* ~CopyBF - Copy a bit field
+10
View File
@@ -4232,6 +4232,7 @@ lb1 clc restore the original argp+4
* ~Format_x - format a hexadecimal number (lowercase output)
* ~Format_X - format a hexadecimal number (uppercase output)
* ~Format_p - format a pointer
* ~Format_b_C23 - format a binary number (lowercase prefix, if any)
* ~Format_B - format a binary number (uppercase prefix, if any)
*
* Inputs:
@@ -4253,6 +4254,10 @@ argp equ 7 argument pointer
lda #3 use 3 bits per output character
bra cn0a
~Format_b_C23 entry
ldx #$20*256 set the "or" value for case of '0b'
bra bn0
~Format_B entry
ldx #0
bn0 lda #1 use 1 bit per output character
@@ -4392,6 +4397,11 @@ argp equ 7 argument pointer
bra lb0
~Format_b entry
dc i1'$A9' lda #~C23orLater (if linked in) or #0
dc s2'~C23ORLATER' (this must be on a separate line)
beq ~Format_P if doing C23 or later then
brl ~Format_b_C23 use C23 version of 'b' format
~Format_P entry
clc set flag for p-string