checking for overflow in C

Tom Neff tneff at bfmny0.UUCP
Sun May 7 13:35:00 AEST 1989


Let me agree with and amplify on Henry Spencer's customarily excellent
remarks, namely that C can't always check things like overflow because
it has to be portable.  There do exist high level languages which cater
to every hardware feature of a family of processors.  On the Intel *86
family PL/M is a perfect example.  Based originally on PL/I Subset (I
will mail a chocolate chip cookie to anyone who ever programmed in
THAT particular late 60s IBM brainchild!!), PL/M has hardware builtins
for virtually everything special about the 8086/88, 286, 386 and now 486.
You use them as functions or procedures in your statements, or sometimes
they are standalone statements like "DISABLE;".  However PL/M is monumentally
non-portable to other architectures, as we know our minimal discomfort
at my employers'.

C on the other hand is signally portable, and incorporates the minimum
of assumptions about how its host processor is going to behave.  Henry
is dead to rights: if your C program needs to worry about integer overflow
in a particular situation, let it check the values beforehand rather than
waiting for the CPU or OS to save its bacon.
-- 
Tom Neff				UUCP:     ...!uunet!bfmny0!tneff
    "Truisms aren't everything."	Internet: tneff at bfmny0.UU.NET



More information about the Comp.lang.c mailing list