mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Pascal Cuoq <cuoq@trust-in-soft.com>
To: "musl@lists.openwall.com" <musl@lists.openwall.com>
Subject: [musl] STRUCT _IO_FILE { char __x; }; as the poor C programmer's abstract struct
Date: Wed, 6 Oct 2021 13:49:16 +0000	[thread overview]
Message-ID: <PR0P264MB07948825F6A478D20A7F2AF3C0B09@PR0P264MB0794.FRAP264.PROD.OUTLOOK.COM> (raw)

Hello,

The file stdio.h contains:

#if __STDC_VERSION__ < 201112L
#define __NEED_struct__IO_FILE
#endif
…
#include <bits/alltypes.h>

And the file alltypes.h is generated from alltypes.h.in which contains:

STRUCT _IO_FILE { char __x; };
TYPEDEF struct _IO_FILE FILE;

This means that when the compiler defines __STDC_VERSION__ to less than 201112L, a bogus definition for the type FILE and for the prototypes of functions that access values of this type can exist in files outside musl, alongside the real definition from stdio_impl.h which exists in files inside musl:

struct _IO_FILE {
        unsigned flags;
        unsigned char *rpos, *rend;
        int (*close)(FILE *);
 …

This is at least a minor annoyance when trying to do source-level verifications on a mix of source files including some files that implement musl together with some files that use musl from the outside.

Was it only in C11 that it became possible to avoid this ugly hack?

(We stumbled on this because we happened to be doing the pre-processing with -std=c99, and I think it should be no problem to change it to be done with -std=c11, but I'm surprised nevertheless because I don't see which item in https://port70.net/~nsz/c/c11/n1570.html#Forewordp6 corresponds to this change between C99 and C11. Could the test be changed to “__STDC_VERSION__ < 199901L”?)

Pascal



             reply	other threads:[~2021-10-06 13:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 13:49 Pascal Cuoq [this message]
2021-10-06 15:43 ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PR0P264MB07948825F6A478D20A7F2AF3C0B09@PR0P264MB0794.FRAP264.PROD.OUTLOOK.COM \
    --to=cuoq@trust-in-soft.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).