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.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think!linus!emery From: emery@linus.mitre.org (David Emery) Newsgroups: comp.lang.ada Subject: Re: C Strings in Ada? Message-ID: Date: 12 Jun 90 14:04:06 GMT References: <920024@hpclapd.HP.COM> <920026@hpclapd.HP.COM> Sender: usenet@linus.mitre.org Organization: The Mitre Corporation, Bedford, MA In-reply-to: defaria@hpclapd.HP.COM's message of 11 Jun 90 22:39:00 GMT List-Id: defaria@hpclapd.hp.com writes >My understanding is that the compiler would allocate space on the stack for >this variable if the size of STRING_PARAM can be determined at compile time >not at run time. Since STRING_PARAM is being passed into my routines it is >not known, at compile time, how big the STRING_PARAM will be (it could >theoretically (sp?) be INTEGER'LAST bytes long!! There is no requirement (in Ada or any other language) that only objects who size is static at compile-time be allocated off the stack. The requirement, instead, is that the size of the object be STATIC at runtime. The size of STRING_PARAM is known when the stack frame for the block is built. For instance, if STRING_PARAM is 7 characters long, then a string of length 7 is allocated off the stack. Almost any block-structured language can do this (including C and Pascal). To insure that the object being declared (C_STRING) remains static, it is declared as a constant. Ada provides substantial support for types and subtypes whose size is not known until runtime. There are some things you can't do with them, but in general storage allocation is not a problem. That is because all objects in Ada are required to be constrained, either with a fixed size, or with a maximum size. In the case of variant records with defaults, the maximum size is determinable based on the range of values of the discriminant. There is always the problem with overflowing either stack or heap. If you have a string where 'LENGTH = INTEGER'LAST, I doubt that it will fit anywhere in main memory, and you'll get STORAGE_ERROR long before you try to append a ASCII.NUL to it and pass it to C. dave emery emery@aries.mitre.org