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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC 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: Alan Brain Subject: Re: Ada and robots Date: 1997/06/27 Message-ID: <33B4768B.75CA@dynamite.com.au>#1/1 X-Deja-AN: 252920400 References: <9706262213.AA13647@stealth.ctron.com> Organization: @Home Reply-To: aebrain@dynamite.com.au Newsgroups: comp.lang.ada Date: 1997-06-27T00:00:00+00:00 List-Id: Huy Vo wrote: > Someone has to care, Jon. Because if you dynamically allocate memory > at 101 places in your 100K lines of code and only one of > the allocations failed, you really want to know which one failed. > As an application programmer what would you do? As a compiler writer > that has to provide a default handler for this type of situation > what would you do? > > 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); > } > > Show me your code. In Ada-83, when STORAGE_ERROR => PUT("Storage Error for Module: " & ModuleName & " At line: "); PUT(LineCount); raise; Naturally this means you must set variables ModuleName (a string) and LineCount (a positive) in the code. You also need to have with TEXT_IO; use TEXT_IO. and exception somewheres. But as your C code didn't mention the #includes required for the use of stderr, fprintf, and the non-portable definition of __LINE__ I think this is fair. Especially since the Ada is completely portable. Oh yes, the "raise" statement doesn't just give a meaningless error code (1), it tells the caller that this is a STORAGE_ERROR, and allows them to use a different technique/algorithm that won't be so memory-intensive. -- aebrain@dynamite.com.au <> <> How doth the little Crocodile | Alan & Carmel Brain| xxxxx Improve his shining tail? | Canberra Australia | xxxxxHxHxxxxxx _MMMMMMMMM_MMMMMMMMM 100026.2014 compuserve o OO*O^^^^O*OO o oo oo oo oo By pulling MAERKLIN Wagons, in 1/220 Scale See http://www.z-world.com/graphics/z/master/8856.gif for picture