Skip site navigation (1) Skip section navigation (2)

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

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
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 10:04:06
Message-ID: 200704011204.07451.peter_e@gmx.net (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
Gregory Stark wrote:
> > 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.

How so?

> 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.

But character constants are actually ints, so when you do what you 
describe then the compiler has to generate code to copy a four-byte 
integer into a single byte.  (Of course that can be optimized away, 
probably.)

> 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.

The standard says that enums are the same as ints.  So when you assign 
an enum label to a char variable, then compiler has to generate code to 
copy a four-byte integer into a single byte.  (Of course that can be 
optimized away, probably.)

The fact that you can also declare variables of the enum type is not 
under consideration here.

QED

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/

In response to

pgsql-hackers by date

Next:From: Martijn van OosterhoutDate: 2007-04-01 10:30:51
Subject: Re: Bug in UTF8-Validation Code?
Previous:From: Gregory StarkDate: 2007-04-01 09:36:39
Subject: Re: Macros for typtype (was Re: Arrays of Complex Types)

pgsql-patches by date

Next:From: Magnus HaganderDate: 2007-04-01 13:25:58
Subject: Re: bgwriter stats
Previous:From: Gregory StarkDate: 2007-04-01 09:36:39
Subject: Re: Macros for typtype (was Re: Arrays of Complex Types)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group