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,e723b158fb4ad12e X-Google-Attributes: gid103376,public From: nobody@REPLAY.COM (Anonymous) Subject: Re: Initialized global data Date: 1998/05/06 Message-ID: <199805061414.QAA14832@basement.replay.com>#1/1 X-Deja-AN: 350775229 Content-Transfer-Encoding: 7bit References: <6iosc2$3mp@bgtnsc01.worldnet.att.net> Content-Type: text/plain; charset=us-ascii Organization: Replay Associates, L.L.P. Mail-To-News-Contact: postmaster@nym.alias.net X-001: Replay may or may not approve of the content of this posting X-002: Report misuse of this automated service to X-URL: http://www.replay.com/remailer/ Newsgroups: comp.lang.ada Date: 1998-05-06T00:00:00+00:00 List-Id: On Tue, 05 May 1998 22:24:45 -0700, Kevin Wells wrote: > When specifying data in an Ada package that is pre-initialized such as > ---------------------------------------- > package Generate_Matrix is > Scale_Factor : float := 10.903; > . > end Generate_Matrix; -- spec > ---------------------------------------- > > 1. Is it normal for the compiler to generate code that sets the value in > memory > (that gets executed when the runtime system is initialized)? Yes. > 2. Is there a way to get around this? You might try pragma Preelaborate (Ada only; not available in Ada 83). > > I am trying to create pre-initialized data arrays in memory such as > ---------------------------------------- > type Array_Type is array (1 .. 5) of integer; > Small_Array : Array_Type := (1, 10, 5, 9, -50); > ---------------------------------------- > but the compiler generates a bunch of code to set those 5 memory > locations. > ... The general rule for global variables is: Never use global variables. If these are not actually variables, they should be constants: Scale_Factor : constant := 10.903; -- OR ": constant Float :=" Small_Array : constant Array_Type := (1, 10, 5, 9, -50); In the case of named numbers (X : constant := 7.3;), the compiler should not generate any code or allocate any memory. In the case of typed constants (X : constant T := V;), both may occur. Pragma Preelaborate might take care of this for you. If the numbers are in ROM, you have to be able to get around this. You might be able to use a deferred constant with a pragma Import (Ada only): X : constant T; pragma Import (Convention, X, "Name_Of_X"); Ask your compiler vendor. Or you can use an uninitialized "variable" (that doesn't) at a specified address: X : T; for X'Address use A; -- Ada 83: "for X use at A;" The compiler might then warn you that you are accessing undefined values, but you know you can ignore these warnings. Jeff Carter PGP:1024/440FBE21 My real e-mail address: ( carter @ innocon . com ) "I waggle my private parts at your aunties." Monty Python & the Holy Grail Posted with Spam Hater - see http://www.compulink.co.uk/~net-services/spam/