Re: Patch to include c.h - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Patch to include c.h
Date
Msg-id 12292.1347810774@sss.pgh.pa.us
Whole thread Raw
In response to Patch to include c.h  (Gurjeet Singh <singh.gurjeet@gmail.com>)
Responses Re: Patch to include c.h
List pgsql-hackers
Gurjeet Singh <singh.gurjeet@gmail.com> writes:
> I noticed that xlog.h uses PGDLLIMPORT, but it does not include c.h
> directly or indirectly.

In general, all include files in Postgres assume that you've included
postgres.h or postgres_fe.h (as appropriate) first; and practically
all of them have far more dependencies on that than you mention here.
If we were to decorate them with explicit inclusions such as you propose,
we would accomplish little except to bloat the sources and slow down
compilation.

The general rule about that is "thou shalt have no other gods before
c.h" --- that is, it is *necessary* that c.h be included before anything
else, in *every* Postgres file.  Otherwise you can run into
platform-specific problems.  An example I remember is individual files
having different ideas of whether 64-bit or 32-bit filesystem APIs are
in use, as a consequence of <stdio.h> being read before pg_config_os.h
has defined symbols controlling that.  Needless to say, this doesn't
work well at runtime.  You can find actual examples of that sort of
thing in the archives from years ago, before we began to enforce the
rule rigidly.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: _FORTIFY_SOURCE by default?
Next
From: Tom Lane
Date:
Subject: Possible fix for occasional failures on castoroides etc