Re^3 (was 2): struct comparison
Donn Terry
donn at hpfcdc.HP.COM
Mon Jul 24 11:20:58 AEST 1989
Personal opinion:
Omitting comparison of at least a limited range of structs presents
a class of problems that has not been addressed here so far.
There are certain predefined types in classical UN*X (and probably other
OSs as well) that would "like" to be structs (or at least objects larger
than long). dev_t is a good example. For historical reasons, usually
associated with comparisons on such types, they must be constrained to
integral (or at least arithmetic) types.
Because ANSI C prohibits comparisons on such larger types, standardizers
of other things (e.g. POSIX) are constrained:
1) require integral/arithmetic types, and force unnatural kluges
on some OS's (more than 32-bits worth of I/O addressability,
allowing for type modifiers: try to cram it into an dev_t or
force an otherwise unneeded long long long long... type).
2) Define new types for the standard, and define operations on
those types for all relevant operations. (Typically at least
3: comparison, and some modifier and it's converse.)
3) Break existing applications by permitting/requiring struct types
that will break the applications that use the object.
If ANSI C had permitted even a strongly constrained comparable struct type
these problems would have been eliminated. (E.g. add "comparable" struct
to the language: compilers would be permitted to reorder to allow comparison
as a byte-by-byte comparison; possibly prohibit pointers, possibly prohibit
or constrain unions.) Even off_t would have been helped, as only the add
and subtract operators would have to be macros were this possible. Those
are not _too_ common.
(Something has to give with off_t, and soon; 4Gb disks are coming along
very soon. It would be nice to find a way to deal with them without
having to rewrite every use of off_t and lseek() in the world. The
ANSI C solution might work (I forget the names, but there is a solution
for stdio), but it does require a lot of rewrite of existing applications.)
Donn Terry
HP Ft. Collins
Chair 1003.1 (and speaking only for himself)
More information about the Comp.std.c
mailing list