Thread: Question about "name" datatype

Question about "name" datatype

From
Greg Stark
Date:
In c.h There is the following comment:

/** We want NameData to have length NAMEDATALEN and int alignment,* because that's how the data type 'name' is defined
inpg_type.* Use a union to make sure the compiler agrees.  Note that NAMEDATALEN* must be a multiple of sizeof(int),
elsesizeof(NameData) will probably* not come out equal to NAMEDATALEN.*/
 


And indeed in pg_type the typalign column says "i" for this data type. My
question is just, why? What would be the problem with an alignment of 1 for
"name"?

-- 
greg



Re: Question about "name" datatype

From
Tom Lane
Date:
Greg Stark <gsstark@mit.edu> writes:
> And indeed in pg_type the typalign column says "i" for this data type. My
> question is just, why? What would be the problem with an alignment of 1 for
> "name"?

Probably none, but that's how it's been defined since day one, and there
doesn't seem any good reason to change.  (Looking at the system catalog
definitions, it doesn't appear that we'd save anything on alignment.)

It's possible that back when that decision was taken, there was
something in the bootstrap code that wouldn't work with non-int-aligned
columns?  Just a guess.
        regards, tom lane