Re: How to include the header files effectively - Mailing list pgsql-hackers

From Tom Lane
Subject Re: How to include the header files effectively
Date
Msg-id 21603.1555035674@sss.pgh.pa.us
Whole thread Raw
In response to How to include the header files effectively  (Andy Fan <zhihui.fan1213@gmail.com>)
List pgsql-hackers
Andy Fan <zhihui.fan1213@gmail.com> writes:
> for example,  when I want the LOCKTAG in .c file,   which is defined in
> "storage/lock.h".  then I wrote the code like this:

> #include "storage/lock.h"
> ...
> LOCKTAG tag;

> compile and get errors.

> In file included from
> .../src/include/storage/lock.h:21:
> /../../../src/include/storage/lockdefs.h:50:2: error: unknown type name
>       'TransactionId'
>         TransactionId xid;                      /* xid of holder of
> AccessExclusiveLock */

The reason that's failing is that you didn't include postgres.h first.

The general expectation --- and we do mechanically verify this,
periodically --- is that any Postgres header should have enough #include's
that you can include it without further work, so long as you included
postgres.h (or postgres_fe.h, or c.h, depending on context) beforehand.
One of those three headers must be the first inclusion in every Postgres
.c file.  There are portability reasons behind that rule, which you
don't really want to know about ;-) ... just do it like that.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Andy Fan
Date:
Subject: How to include the header files effectively
Next
From: Alvaro Herrera
Date:
Subject: Re: How to include the header files effectively