Can we rely on #pragma once ?

Peter Hutterer peter.hutterer at who-t.net
Tue Feb 20 00:41:41 UTC 2024


On Mon, Feb 19, 2024 at 03:02:18PM +0100, Mark Kettenis wrote:
> > Date: Mon, 19 Feb 2024 12:13:34 +0100
> > From: "Enrico Weigelt, metux IT consult" <info at metux.net>
> > 
> > Hello folks,
> 
> Hi Enrico,
> 
> > we've got a lot of include files, therefore lots of guards.
> > 
> > Modern C compilers should understand #pragma once, but this isn't
> > without problems (possibly problematic with symlinks ?), and I have
> > to admit I don't how well is it supported outside of GNU land.
> > 
> > Can we rely on it ?
> 
> IMHO, no.  There must be a reason why this hasn't been widely adopted,
> despite having been around for the better part of 2- years.  

maybe just inertia? the ifdef guards work just fine, pragma is nice for
new headers but few people would be motivated to go and replace all
ifdefs to pragmas just for entertainment value.

meson uses pragma once for its generated headers (e.g. dix-config.h) so
any compiler that managed to build an X server recently supports it.

> And the
> public Xorg headers should work with a standard C99 compiler.
> 
> To be honest, some of the things you've raised in this thread really
> worry me.  I don't think Xorg is in a position where it makes sense to
> do a large overhaul.  The code is used by a lot of projects, but many
> of those projects probably don't have a lot of manpower to spend on
> testing Xorg patches.  So breakage may not be caught in a timely
> fashion unless you commit yourself to testing a wide variety of
> platforms.

fully agree here. *we* don't have the manpower to test those patches,
the CI is nice and worlds better than what we used to have (which was,
well, nothing) but it's not going to catch much beyond build errors.

Cheers,
  Peter
 
> Looking at this particular thing, what problem are you trying to
> solve?  The existing header files already have the protection in place
> where it matters.  And I don't expect why software that's mostly just
> in maintenance mode would see a lot of new header files being added.


> 
> > In fact, we already have one place using it:
> > 
> > include/xwayland-config.h.meson.in
> > 
> > But I doubt that xwayland is ever been compiled w/ non-gnu/non-clang
> > compilers.


More information about the xorg-devel mailing list