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=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1042f393323e22da X-Google-Attributes: gid103376,public From: "Nick Roberts" Subject: Re: Any research putting c above ada? Date: 1997/04/20 Message-ID: <01bc4da6$70afa380$f4f582c1@xhv46.dial.pipex.com>#1/1 X-Deja-AN: 236193302 References: <5ih6i9$oct$1@waldorf.csc.calpoly.edu> <5ijb0o$ajc@ns1.sw-eng.falls-church.va.us> <334d3da5.14386594@aplcen.apl.jhu.edu> <2senchydgk.fsf@hpodid2.eurocontrol.fr> <5im3an$3dv@bcrkh13.bnr.ca> <33526cbf.41c6@cca.rockwell.com> <5iusvd$118e@newssvr01-int.news.prodigy.com> <3353a187.1062@bix.com> <5j19on$u82@newssvr01-int.news.prodigy.com> <33545F8D.2AF4@worldnet.att.net> <335569F1.55A0@pratique.fr> Organization: UUNet PIPEX server (post doesn't reflect views of UUNet PIPEX) Newsgroups: comp.lang.ada Date: 1997-04-20T00:00:00+00:00 List-Id: In answer to the questions about putting different fruits in the same array, have a gander at this: ----------- type Kind_Of_Fruit = (Apple, Orange, {other kinds}); type Fruit_Descriptor(Kind: Kind_Of_Fruit) is record case Kind is when Apple => AV: Apple_Variety; {other components} when Orange => OV: Orange_Variety; {other components} {etc for other kinds} end case; end record; type Fruit_Reference is access Fruit_Descriptor; ... FA: array (Location_In_Bowl) of Fruit_Descriptor; ... begin FA(1) := new Fruit_Descriptor'(Apple,Golden_Delicious,...); FA(2) := new Fruit_Descriptor'(Orange,Satsuma,...); ... end; ------------ Thus one might (want to) have different fruits in the same array. The above can be done in C++ using classes, but in order to get the equivalent of Ada's automatic deallocation, the appropriate destructor has to be declared. This is not difficult, but it's easier (and less error-prone) in Ada. To do this in C is not directly possible. The deallocation has to be done specifically, and the correct size has to be specified when allocating each fruit (since the size of an apple descriptor may be different to that of an orange, and other fruits). In addition, nothing prevents apple data and orange data being mixed up accidentally (lint can only check static contraventions). This is really a pain, and illustrates how C is not very suitable for large-scale software. Nick.