From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5ecb5248e650e812 X-Google-Attributes: gid103376,public From: ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) Subject: Re: Ada and robots Date: 1997/06/27 Message-ID: <5ovcgk$6f4$1@goanna.cs.rmit.edu.au>#1/1 X-Deja-AN: 254692258 References: <9706262213.AA13647@stealth.ctron.com> Organization: Comp Sci, RMIT University, Melbourne, Australia. Newsgroups: comp.lang.ada NNTP-Posting-User: ok Date: 1997-06-27T00:00:00+00:00 List-Id: Huy Vo writes: >In C, it's as simple as > if (!(cp =malloc(BIG_CHUNK)) { > fprintf(stderr, "Buy some more ram, i died at line %d\n", __LINE__); > exit(1); > } A nice example of what can go wrong with C. (1) exit(1) is not portable. (At my suggestion, lclint can check for this.) In some important C systems, exit(1) indicates _success_, not failure. It should be exit(EXIT_FAILURE), or better still, abort(). (2) A typical C program has many more source files than one. If you tell me what line number, what good does that do? (3) "Good" C for this would be something like #define New(p, n) \ if (((p) = malloc((n))) != 0) {} else assert(!"malloc failed") which will, I'm afraid, provoke warnings from lint and other checkers (empty if-part, constant condition). -- Four policemen playing jazz on an up escalator in the railway station. Richard A. O'Keefe; http://www.cs.rmit.edu.au/%7Eok; RMIT Comp.Sci.