Keith Thompson <[email protected]> wrote: > It appears that `#include <stdio.h>` implicitly causes `<stddef.h>` to be > included. > I haven't tracked down how this happens. this is an issue - it's incorrect behavior > > I'm using the latest version of tinycc (commit 3e8f1da9, 2025-11-17), > built from source on Ubuntu x86_64 24.04.3. a glibc system > > This program compiles without error. (gcc and clang correctly diagnose the > errors.) in this case, this happens because tcc uses glibc's stdio.h, then finds a stddef.h to use tcc doesn't ship its own stdio.h, but it does have a stddef.h
based on the differences between musl/glibc, glibc is wrong
here is a short excerpt of the stdio.h shipped in that package:
19 #ifndef _STDIO_H
20 #define _STDIO_H 1
21 #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
22 #include <bits/libc-header-start.h>
23 __BEGIN_DECLS
24 #define __need_size_t
25 #define __need_NULL
26 #include <stddef.h>
as you can see, line 26 includes stddef.h - the only condition is that
_STDIO_H isn't defined
since stdio.h requires size_t, glibc opts to define __need_size_t,
which is what glibc expects stddef.h to define, no ptrdiff_t, etc. - a
nonstandard mess, and not how stddef.h should work!
some options:
- don't use glibc's stdio.h (use a different stdio.h)
- don't use glibc
- report this as a bug at glibc's tracker, if a ticket doesn't
exist already
- live with it, do nothing. not tcc's bug
--
reproducible on glibc 2.42+r17+gd7274d718e6f-1 (artix linux)
CC=gcc version 15.2.1 20250813 (GCC) (options break tcc build on
makepkg@b8b6a5fd, same stddef.h issue with different flags)
./configure --dwarf=5 --debug --enable-static --config-backtrace=no
--extra-ldflags=-static
make
tcc version 0.9.28rc 2025-11-17 HEAD@3e8f1da9 (x86_64 Linux)
./tcc bla.c
In file included from bla.c:1:
/usr/include/stdio.h:34: error: include file 'stddef.h' not found
compiles without an error:
./tcc -L . -I include/ ./bla.c
brilliant.
yes, stddef.h doesn't exist in the glibc package - and I haven't
allowed tcc to place one
the gcc package ships its own version:
gcc /usr/lib/gcc/x86_64-pc-linux-gnu/15.2.1/include/stddef.h
this regressed recently, this version compiles it just fine:
tcc version 0.9.28rc 2024-09-14 makepkg@b8b6a5fd (x86_64 Linux)
tcc can't and shouldn't do anything about nonstandard .h files - that's
overengineering
doesn't happen on musl
(CC=tcc version 0.9.28rc 2025-09-18 mob@de8c19e1 (x86_64 Linux))
./configure --dwarf=5 --config-musl --debug --enable-static
--config-backtrace=no --extra-ldflags=-static
make
./tcc --version
tcc version 0.9.28rc 2025-11-17 HEAD@3e8f1da9 (x86_64 Linux)
./tcc ./bla.c
./bla.c:3: error: 'ptrdiff_t' undeclared
tcc uses musl's stdio.h, which doesn't include stddef.h.
check with 'tcc -E bla.c'
signature.asc
Description: PGP signature
_______________________________________________ Tinycc-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/tinycc-devel
