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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,df854b5838c3e14 X-Google-Attributes: gid103376,public From: Doug Rogers Subject: Re: Gripe about Ada, rep specs that won't. Date: 1996/03/22 Message-ID: <4iv0g6$6cs@news4.digex.net> X-Deja-AN: 143744532 references: <00001a73+00002504@msn.com> <4iq71v$cvr@news4.digex.net> <4isol4$dm7@ra.nrl.navy.mil> content-type: text/plain; charset=us-ascii organization: Innovative Concepts, Inc. x-url: news:Don8H5.AKI@world.std.com mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 1.1N (X11; I; Linux 1.2.4 i486) Date: 1996-03-22T00:00:00+00:00 List-Id: bobduff@world.std.com (Robert A Duff) wrote: >Well, here's some more preaching: >No, you cannot access the fields from the wrong variant. >A run-time check on the discriminant is done. >Ada *does* protect you from that particular hole. >Why do you believe otherwise? Because I've never had C_E raised when doing so. I stand corrected. As suggested, I begrudgingly accept. >>I'm using GNAT for prototyping. Here's my vote for packed types of all >>sizes. >I imagine that if you and enough others paid ACT for a support contract, >they would implement it. I agree, it would be nice to have this >support. Not quite nice enough to require in the Standard, though. That's why I think Ada, despite its many advantages over other languages, won't prosper. That's why embedded designers cringe. We spend many man-months just overcoming these "little" obstacles. It's only taxpayer money, though. ;) Last night I spent an hour writing up a mortgage tabulation program in Ada, and you know what? It was cake. But you know what else? It only did text IO. Okay. I humbly submit a request to the Ada community at large. I'd like to know a good way to do the following: type Nat4 is 0 .. (2 ** 4) - 1; -- 0 .. 7#21# :) :> for Nat4'size use 4; type Nat9 is 0 .. (2 ** 9) - 1; -- 0 .. 25#JB# oh, different thread for Nat9'size use 9; type Nat16 is 0 .. (2 ** 16) - 1; for Nat16'size use 16; type Items is record Piece_1 : Nat4; Piece_2 : Nat9; end record; for Items use record Piece_1 at 0 range 0 .. 3; Piece_2 at 0 range 4 .. 12; end record; for Items'size use 13; -- Now for the tricky part, I need an array of these bad boys: type Item_Lists is array (integer range 0 .. 23) of Items; -- And this won't work (under the 3 implementations I've tried): pragma Pack (Item_Lists); -- Something like this is at the beginning of the file: type Headers is record List_Count : Nat16; First : Nat16; Last : Nat16; end record; And, now, to make matters worse, I'd like to read this record, mixed in with Headers, from a binary file. If you have any ideas at all, I'm willing to entertain them. The best solution I've found so far is to create packed arrays of bits wherever it turns out to be necessary. I'm toying around with the idea of using ONLY packed arrays of bits at the interface level (the file IO), but that means I can use the compiler for very little checking. I've tried creating a generic convertor from a packed bit array into any other type, but I can't use Element_Type'size to set the bit-array size in the generic, nor can I set the size to be big ('cause then the compiler -- GNAT, anyway -- says that I must specify EXACTLY Element_Type'size inside a rep clause, and the size is known as a static, only by the instantiating unit). I'm left with a mish-mash approach, mixing records and bit-arrays seemingly at random, or with unchecked conversions of pointers (ugh!) sprinkled everywhere. Either way isn't even close to the elegance of the unsupported "solution" above. I want to stress that I have run into this problem on EVERY project that I've used Ada (with the exception of cute little ammortization schedule programs). My current project isn't even an embedded system. It's just handling a stream of satellite telemetry. This problem is faced and conquered every day. And that's my point. Those Boeing 777 folk must be awesome ('cause the one I was on flew perfectly and landed without a hitch! :-). >>Sequential_Mixed_IO for GNAT, but since it uses System.File_IO and >>various other Ada95-specific packages, I can't use -gnat83. >Surely only the *body* of your package depends on System.File_IO, so >surely you can compile *most* of your code with the -gnat83 switch? Sorry for the confusion. I didn't mean that .File_IO was standard in any way. I'm using it only as a means to compile my code completely, and even run it, under Linux without having to spend all day ftp-ing back and forth to an Alpha OpenVMS station. You're correct. The body depends on it. But (correct me again if I'm wrong again), there are generic procedures in the package, so the body of any package that uses my Seq_Mix_IO package will "use" the body of Seq_Mix_IO. I get: gcc -c -gnat83 ephemerae.adb sequential_mixed_io.adb:20:06: (Ada 83) child units not allowed ..for each instance of the generic Put/Get Perhaps I should change the subject and list my (reduced) source. Doug -- =------cxiuj-opinioj-estas-sole-miaj.-----any-opinions-are-mine-alone.------= = Doug Rogers vocxe/voice = 1.703.893.2007 fakse/fax = 1.703.893.5890 = = Innovative Concepts Inc; 8200 Greensboro Drive Suite 801; McLean VA 22102 = = PGP ID: pub 1024/016DE91D 1994/11/14 Doug Rogers = =senemankasalvimultodatempolernulaanglan-ifyouvegotalittletimelearnesperanto=