1: Sample code that reproduces the problem.
int hosted = __STDC_HOSTED__;
2: Exact command used to run SDCC on this sample code.
sdcc -mz80 --std=c2y -E bug.c
3: SDCC version tested.
SDCC 4.6.4 #17068 (Linux), tested 23 October 2026.
4: Observed and expected behaviour.
The preprocessed declaration is int hosted = 1;.
Section 3.1 of the published SDCC 4.6.4 manual describes its intended implementation model as freestanding. Under that model, STDC_HOSTED should expand to 0. N3886 6.10.10.2 defines this macro as 1 for a hosted implementation and 0 otherwise. Reporting 1 makes environment-dependent source code select its hosted branch instead.
The report is about consistency with SDCC's documented freestanding model. It does not infer that hosted startup constraints apply to SDCC merely because the preprocessor currently reports 1. The driver/model contract and predefined macro should agree.
References: SDCC Compiler User Guide, section 3.1, page 25; N3886, 6.10.10.2.
5: Additional checks.
The default result is 1 on Z80, MCS51, STM8, PDK14 and MOS65C02 in both C23 and C2Y (10 checks). The same commands with -Wp-ffreestanding produce 0 in all ten configurations. These commands do not use --nostdinc, so the result is not an artefact of disabling standard-header lookup. The explicit preprocessor flag demonstrates a way to obtain the expected value.
GCC 13.3.0 reports 1 in its default hosted mode and 0 with -ffreestanding, as expected. GCC 16.2 and Clang were not tested.
Diff:
Maybe this broke at one of the sdcpp rebases on newer upstream cpp from GCC? @felixs?
Or has it ever worked?
I just tried arm-none-eabi-gcc 11.2..0 and it also reports to be hosted by default.
bug-4209.c
Note that this compiler is used to compile e.g. U-boot, the bootloader to start Linux on many embedded platforms.
Arguing that this is dependent on the used C library and newlib-nano clearly states it is not hosted, I retried with arm-none-eabi-gcc --specs=nano.specs, but that changes nothing.
The fix for this appears to be trivial. I am attaching it for review. I assume it still needs approval from another developer according to policy.
Looks good to me.
Thanks for the review. Fixed by [r17142].
Related
Commit: [r17142]
There is an issue with the test case, looks like the regression test infrastructure has problems parsing the header and/or indentifying the test functions:
Removed a colon from the opening comment in the test file. [r17150]
Related
Commit: [r17150]