Stack Overflow user "pmor" has put together a C source file that
demonstrates a large number of similar problems, identifiers that
should not be visible in a strictly conforming compiler but are
visible with "gcc -std=c11 -pedantic".

A few of the symbols, namely gmtime_r, localtime_r, and timegm,
are declared in <time.h> in C23, but not in earlier editions
of the C standard.  They should not be visible unless
you use "-std=c23" or "-std=gnu23" (the latter is the default
in more recent versions of gcc.

The program is here:

https://godbolt.org/z/Pr1obzYxx

And just in case that link isn't permanent, here's the code:

#include <assert.h>
#include <iso646.h>
#include <stdarg.h>
#include <string.h>
#include <complex.h>
#include <limits.h>
#if __STDC_NO_ATOMICS__ != 1
#include <stdatomic.h>
#endif
#include <tgmath.h>
#include <ctype.h>
#include <locale.h>
#include <stdbool.h>
#include <time.h>
#include <errno.h>
#include <math.h>
#include <stddef.h>
#include <uchar.h>
#include <fenv.h>
#include <setjmp.h>
#include <stdint.h>
#include <wchar.h>
#include <float.h>
#include <signal.h>
#include <stdio.h>
#include <wctype.h>
#include <inttypes.h>
#include <stdalign.h>
#include <stdlib.h>

typedef struct { int x; } T;

T BUS_ADRALN;
T BUS_ADRERR;
T BUS_OBJERR;
T CLD_CONTINUED;
T CLD_DUMPED;
T CLD_EXITED;
T CLD_KILLED;
T CLD_STOPPED;
T CLD_TRAPPED;
T FPE_FLTDIV;
T FPE_FLTINV;
T FPE_FLTOVF;
T FPE_FLTRES;
T FPE_FLTSUB;
T FPE_FLTUND;
T FPE_INTDIV;
T FPE_INTOVF;
T ILL_BADSTK;
T ILL_COPROC;
T ILL_ILLADR;
T ILL_ILLOPC;
T ILL_ILLOPN;
T ILL_ILLTRP;
T ILL_PRVOPC;
T ILL_PRVREG;
T SEGV_ACCERR;
T SEGV_MAPERR;
T SIGEV_NONE;
T SIGEV_SIGNAL;
T SIGEV_THREAD;
T SI_ASYNCIO;
T SI_KERNEL;
T SI_MESGQ;
T SI_QUEUE;
T SI_TIMER;
T SI_USER;
T addr_t;
T asctime_r;
T blkcnt_t;
T blksize_t;
T caddr_t;
T clock_getcpuclockid;
T clock_getenable_attr;
T clock_getres;
T clock_gettime;
T clock_nanosleep;
T clock_setenable_attr;
T clock_setres;
T clock_settime;
T clockid_t;
T cpu_set_t;
T ctime_r;
T daddr_t;
T dev_t;
T error_t;
struct flock { int x; };
T fpurge;
T fsblkcnt_t;
T fsfilcnt_t;
T gammaf;
T getdelim;
T getline;
T getprogname;
T gid_t;
T gmtime_r;
T gnu_dev_major;
T gnu_dev_makedev;
T gnu_dev_minor;
T id_t;
T infinity;
T infinityf;
T ino_t;
struct itimerspec { int x; };
T key_t;
T localtime_r;
T loff_t;
T memalign;
T mkdtemp;
T mode_t;
T nanosleep;
T nlink_t;
T off_t;
T pid_t;
T program_invocation_name;
T program_invocation_short_name;
T psignal;
T pthread_attr_t;
T pthread_barrier_t;
T pthread_barrierattr_t;
T pthread_cond_t;
T pthread_condattr_t;
T pthread_key_t;
T pthread_mutex_t;
T pthread_mutexattr_t;
T pthread_once_t;
T pthread_rwlock_t;
T pthread_rwlockattr_t;
T pthread_spinlock_t;
T pthread_t;
T register_t;
T sbintime_t;
T setprogname;
struct sigaltstack { int x; };
struct sigevent { int x; };
T sigevent_t;
T sigset_t;
struct sigval { int x; };
T sigval_t;
T stack_t;
T strtosigno;
T suseconds_t;
T sys_errlist;
T sys_nerr;
T timegm;
T timelocal;
T timer_create;
T timer_delete;
T timer_getoverrun;
T timer_gettime;
T timer_settime;
T timer_t;
T timespec_t;
T timestruc_t;
T u_int16_t;
T u_int32_t;
T u_int64_t;
T u_int8_t;
T uid_t;
T useconds_t;
T vm_object_t;
T vm_offset_t;
T vm_size_t;
T wcslcat;
T wcslcpy;

int main(void)
{
}


On Thu, Oct 23, 2025 at 8:28 PM Keith Thompson
<[email protected]> wrote:
>
> The "getline" function is specified by POSIX to be declared
> in <stdio.h>.  It is not specified by the ISO C standard, so the
> identifier should be available for use in strictly conforming
> programs.
>
> $ cat getline_bug.c
> #include <stdio.h>
> int getline = 0;
> int main(void) {
>     return getline;
> }
> $ gcc --version
> gcc (GCC) 16.0.0 20250907 (experimental)
> Copyright (C) 2025 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> $ gcc getline_bug.c -o getline_bug
> getline_bug.c:2:5: error: ‘getline’ redeclared as different kind of symbol
>     2 | int getline = 0;
>       |     ^~~~~~~
> In file included from /usr/include/stdio.h:85,
>                  from getline_bug.c:1:
> /usr/include/sys/stdio.h:35:9: note: previous declaration of ‘getline’ with 
> type ‘ssize_t(char **, size_t *, FILE *)’ {aka ‘long int(char **, long 
> unsigned int *, FILE *)’}
>    35 | ssize_t getline (char **, size_t *, FILE *);
>       |         ^~~~~~~
>
> $
>
> Stack Overflow user "pmor" reports the same problem with gcc 12.4.0.
>
> The problem is in newlib, winsup/cygwin/include/sys/stdio.h, line 35.
> I expect getdelim() to exhibit the same problem, but I haven't checked that.
>
> GNU libc's <stdio.h> avoids this problem by surrounding the
> declarations of getline() and getdelim() by an appropriate #ifdef.

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to