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,b971479ef2fe811a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-21 20:46:15 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.mathworks.com!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc02.POSTED!not-for-mail From: "Jeff C," Newsgroups: comp.lang.ada References: Subject: Re: Getting valid Integer values !! X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: NNTP-Posting-Host: 66.31.4.164 X-Complaints-To: abuse@comcast.net X-Trace: sccrnsc02 1066794374 66.31.4.164 (Wed, 22 Oct 2003 03:46:14 GMT) NNTP-Posting-Date: Wed, 22 Oct 2003 03:46:14 GMT Organization: Comcast Online Date: Wed, 22 Oct 2003 03:46:14 GMT Xref: archiver1.google.com comp.lang.ada:1362 Date: 2003-10-22T03:46:14+00:00 List-Id: RE: Getting valid Integer values !! "Beard, Frank Randolph CIV" wrote in message news:mailman.161.1066792253.25614.comp.lang.ada@ada-france.org... -----Original Message----- From: CheGueVerra [mailto:chegueverra@hotmail.com] >> type IntData_Type is range 1000000..9999999; >> IntData : IntData_Type := IntData_Type'first; > would the last line put the value of 1000000 in IntData ? Yes. It's always good to initialize your variables, especially when they have a resticted range. There is no guarantee the variable will contain valid data after the space is allocated. You could get what ever garbage data was left in that memory location. If the data happens to be out of range and you reference it (such as passing the variable into a routine, etc) CONSTRAINT_ERROR will be raised. Frank Funny..I often hear the "Initalize all variables" things but I could not disagree more! (kind of :) The problem is that unless you are initializing it to a value that makes sense in the problem solution domain (e.g. Initilize array index to 'first for some interesting loop construct) I believe you are hurting yourself more than you are helping. The reason is that if you do not initialize it and you get to a segment of the code where you try to use it there are several good things (one of which you list as a bad thing) that can happen 1) The compiler warns you that you are reading from a variable before writing to it. 2) Your cool static analyzer program detects that you are reading from a variable before writing it. (http://www.polyspace.com/product_datasheet/adaverifier.htm) 3) Your human code reviewers detect that you are reading from a variable before writing it. 4) You are smart and use something like GNATs pragma normalize_scalars or Initialize_Scalars to force the compiler to initialize the variables to invalid values so you can get (and eliminate) constraint errors during test and debug. (http://www.cs.kuleuven.ac.be/~dirk/papers/ae02cfmu-paper.pdf) If you initialize everything you do get the added benifit that your program will probably tend to run the same (even if it is wrong (e.g. 'first might be a valid number not not really make sense for how you now intend to use the variable)) ) more often but I think the losses outweight the benefits because even the same "wrongness" could go undetected for years until provided with the magic killer input data. I do agree that if you can reasonable initialize the variable to the value that makes sense for its intended use at time of declaration that you have done a very good thing. But just initializing to some fixed "in range" value is of marginal use.