If C is so evil why is it so successful?

Warner Losh imp at bsdimp.com
Wed Apr 12 13:52:12 CDT 2017


On Wed, Apr 12, 2017 at 12:43 PM, Sean Conner via cctalk
<cctalk at classiccmp.org> wrote:
> It was thus said that the Great Alfred M. Szmidt once stated:
>>    It was thus said that the Great Noel Chiappa via cctalk once stated:
>>    >     > From: Alfred M. Szmidt
>>    >
>>    >     > No even the following program:
>>    >     >   int main (void) { return 0; }
>>    >     > is guaranteed to work
>>    >
>>    > I'm missing something: why not?
>>
>>      Yeah, I'm having a hard time with that too.  I mean, pedantically, it
>>    should be:
>>
>>
>>          #include <stdlib.h>
>>          int main(void) { return EXIT_SUCCESS; }
>>
>> Pedantically, it does not matter -- a return from main is equivalent
>> to an exit(), and exit(0) is sensibly defined, and EXIT_SUCCESS can
>> also be different from 0 (even though I don't think such a platform
>> exists).
>>
>> Similiarly for EXIT_FAILURE ...
>
>   There's this
> (http://stackoverflow.com/questions/8867871/should-i-return-exit-success-or-0-from-main/8868139#8868139):
>
>         Somebody asked about OpenVMS. I haven't used it in a long time, but
>         as I recall odd status values generally denote success while even
>         values denote failure. The C implementation maps 0 to 1, so that
>         return 0; indicates successful termination. Other values are passed
>         unchanged, so return 1; also indicates successful termination.
>         EXIT_FAILURE would have a non-zero even value.
>
>   And certainly VMS is on topic for this list.

The answer is 'it depends' on VMS. I can't recall if it was the C
runtime that was part of VMS, or that was installed by the compiler,
but this was version dependent. The earliest versions of the compiler
that we had, running on 4.4 didn't do the mapping. By the time we'd
upgraded to 4.7 and to a newer compiler, the mapping did happen.
Before exit was a thin wrapper on sys$exit(), but after it wasn't.
This was across both the DEC CC compiler, and the version of gcc
available back in the late 1980's. Interestingly, the old version of
the manual/help file didn't have EXIT_SUCCESS in it, but the new
version did, if memory isn't failing me today. There were a lot of
programs that printed the same message when exit(0) happened, which is
why DEC had to fix it. There was just too many of them. It's my
recollection that it mapped values < 256 in some way that was special,
and values > 256 it passed to sys$exit since all the facilities you'd
create would have high bits set.

But that was coming up on like 30 years ago, so maybe the exact
details fail me. I do know that it change from one version to the
next.

Warner


More information about the cctalk mailing list