Re: How to include the header files effectively

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How to include the header files effectively
Дата
Msg-id 21603.1555035674@sss.pgh.pa.us
обсуждение исходный текст
Ответ на How to include the header files effectively  (Andy Fan <zhihui.fan1213@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Andy Fan
Дата:
Сообщение: How to include the header files effectively
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: How to include the header files effectively