Portablity using structures and malloc - Help

John P. Linderman jpl at allegra.UUCP
Mon Jul 22 06:08:53 AEST 1985


>>> The answer is simple: malloc has been written by someone who knows
>>> the hardware alignment constraints of the machine, and it returns
>>> a pointer that is aligned for *any* use.
>>>
>>> In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
>
> malloc knows, but it's a pity that you can't make malloc tell.
> If there were a nice
>
>     int malign() {return ALIGNMENT_MULTIPLE;}
>
> entry in the malloc package, I could do my own storage allocation.
> A totally trivial one-liner that would make it much easier to write
> portable software.  How about it, system implementors?
>
> John P. Linderman     The much-maligned allegra!jpl

Close, but no cigar, fish-breath.  Don't put the problem on malloc's
doorstep.  Both you and malloc should be able to determine this value, and
a host of others, like minimum alignment required to avoid core dumps,
bits per byte, which release of whose UN*X, paging/non-paging, big/little
endian, host name, number of file descriptors, maximum lengths for
directory entries, path names, arguments passed to exec*, space available
per process, and so on, without building them into your programs.

Some values, like bits per byte, are unlikely to change without forcing a
recompilation, so they could live in a header like
   /usr/include/portable.h
Others, like host name and number of file descriptors, might reasonably be
expected to differ between binary-compatible machines or over time, so
they should be determinable at execution time.  Most of these values are
already available if you know where to look, but knowing where to look is
not portable.  Responsible people on the net [that leaves you out, John]
should collect a list of these values that make porting difficult, and
decide how they can be made known in a standard way.

I suggest that those interested in kicking these issues around move the
discussion to mod.unix, since there is likely to be a lot of overlap of
proposed additions [whence the mod] and since the problems are more those
of UN*X than C [whence the unix].  And why don't you look for a job
commensurate with your skills, Linderman, like waxing VAXes?

John P. Linderman   Departments of Schizophrenia   allegra!jpl



More information about the Comp.unix mailing list