Re: Macros for typtype (was Re: Arrays of Complex Types)

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <pgsql-hackers(at)postgresql(dot)org>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "David Fetter" <david(at)fetter(dot)org>
Subject: Re: Macros for typtype (was Re: Arrays of Complex Types)
Date: 2007-04-01 09:36:39
Message-ID: 87y7lca120.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

"Peter Eisentraut" <peter_e(at)gmx(dot)net> writes:

> Tom Lane wrote:
>> What bothers me about that is I don't think the C spec mandates the
>> representation width. If we could guarantee that enum typtype_type
>> was 1 byte I'd be all for it.
>
> The width is 4 both for the macro and the enum case. Both
>
> #define TYPTYPE_BASE 'b'
>
> and
>
> enum ... {
> TYPTYPE_BASE = 'b',
>
> effectively generate int constants named TYPTYPE_BASE with decimal value
> 98. So there are no storage advantages either way.

That's not accurate at all. The macro case gives you a constant you can only
use to initialize integer variables and members that are explicitly declared
with some integral type. If we consistently declare them "char" then they'll
be predictably 1 byte long.

The enum case does two things. It defines a syntactic meaning for the label,
*and* it defines a thing "enum typtype" which can be used to define variables
and members. If the latter is used then Tom is saying the standard doesn't
specify what width the variable or member will be.

We could use enum {} to define the labels and then make a rule that all actual
variables should be declared using "char" rather than declaring them as "enum
typtype". But I fear somebody would get that wrong some day. The worst thing
is that it might work on their compiler or it might even work on all compilers
and just silently be causing things to be aligned differently than they
expect.

On the other hand it I don't really think it would cause any problems if
people stored their typtypes in integers. Except for the actual FormData_pg_*
structures the precise alignment doesn't actually matter for anything does it?

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2007-04-01 10:04:06 Re: Macros for typtype (was Re: Arrays of Complex Types)
Previous Message Peter Eisentraut 2007-04-01 08:15:29 Re: Macros for typtype (was Re: Arrays of Complex Types)

Browse pgsql-patches by date

  From Date Subject
Next Message Peter Eisentraut 2007-04-01 10:04:06 Re: Macros for typtype (was Re: Arrays of Complex Types)
Previous Message Peter Eisentraut 2007-04-01 08:15:29 Re: Macros for typtype (was Re: Arrays of Complex Types)