Re: Patch to include c.h

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Cc: PGSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch to include c.h
Date: 2012-09-16 15:52:54
Message-ID: 12292.1347810774@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2012-09-16 16:04:16 Possible fix for occasional failures on castoroides etc
Previous Message Tom Lane 2012-09-16 15:26:02 Re: _FORTIFY_SOURCE by default?