Re: undersized unions - Mailing list pgsql-hackers

From Tom Lane
Subject Re: undersized unions
Date
Msg-id 2681670.1675702540@sss.pgh.pa.us
Whole thread Raw
In response to Re: undersized unions  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: undersized unions
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> I do not really know exactly how to do that, though. Our usual pattern
> is to just have a struct and end with a variable-length array, or
> alternatively add a comment says "other stuff follows!" at the end of
> the struct definition, without doing anything that C knows about at
> all. But here it's more complicated: there's a uint16 value for sure,
> and then maybe an int16 value, and then some number of NumericDigit
> values. That "maybe an int16 value" part is not something that C has a
> built-in way of representing, to my knowledge, which is why we end up
> with this hackish thing.

If we were willing to blow off the optimizations for NBASE < 10000,
and say that NumericDigit is always int16, then it would be possible
to represent all of these variants as plain array-of-int16, with
some conventions about which indexes are what (and some casting
between int16 and uint16).

I am, however, very dubious that Andres is correct that there's a
problem here.  Given that two of the variants of union NumericChoice
are structs ending with a flexible array, any compiler that thinks
it knows the size of the union precisely is broken.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: undersized unions
Next
From: Andrew Dunstan
Date:
Subject: Re: run pgindent on a regular basis / scripted manner