From mksmith@cli.com Fri Jul 14 11:41:12 1995 Return-Path: Received: from inmet.camb.inmet.com by dsd.camb.inmet.com (4.1/SMI-4.1) id AA08583; Fri, 14 Jul 95 11:41:12 EDT Received: from sw-eng.falls-church.va.us (ns1.sw-eng.falls-church.va.us) by inmet.camb.inmet.com (4.1/SMI-4.1) id AA11446; Fri, 14 Jul 95 11:41:10 EDT Received: from cli.com by sw-eng.falls-church.va.us (8.6.11/) id PAA13224; Fri, 14 Jul 1995 15:42:09 GMT Received: from ammonite.cli.com by cli.com (4.1/SMI-4.1) id AA26642; Fri, 14 Jul 95 10:40:36 CDT From: mksmith@cli.com (Michael K. Smith) Received: by ammonite.cli.com (4.1) id AA09049; Fri, 14 Jul 95 10:40:33 CDT Date: Fri, 14 Jul 95 10:40:33 CDT Message-Id: <9507141540.AA09049@ammonite.cli.com> To: ada-comment@sw-eng.falls-church.va.us Subject: String literal constraint ramification 4.2(11.a) seems bogus. !topic String literal constraint ramification seems bogus. !reference RM95-4.2(11.a) !from Michael K. Smith 95-07-14 <> !discussion 4.2 (11) states; For the evaluation of a string_literal of type T, a check is made that the value of each character of the string_literal belongs to the component subtype of T. ... The exception Constraint_Error is raised if either of these checks fails. (11.a) RAMIFICATION: The checks on the characters need not involve more than two checks altogether, since one need only check the characters of the string with the lowest and highest position numbers against the range of the component subtype. I don't believe the ramification (or I don't understand it) because package t138 is type Roman_Digit is ('C', 'D', 'I', 'L', 'M', 'V', 'X'); type Roman_Date is array(positive range <>) of Roman_Digit; x : Roman_Date := "CWX"; end; Michael K. Smith Computational Logic Inc. [http://www.cli.com/] Austin, TX Email: mksmith@cli.com From stt@dsd.camb.inmet.com Fri Jul 14 11:59:28 1995 Return-Path: Received: from inmet.camb.inmet.com by dsd.camb.inmet.com (4.1/SMI-4.1) id AA08785; Fri, 14 Jul 95 11:59:28 EDT Received: from sw-eng.falls-church.va.us (ns1.sw-eng.falls-church.va.us) by inmet.camb.inmet.com (4.1/SMI-4.1) id AA11830; Fri, 14 Jul 95 11:59:26 EDT Received: from dsd.camb.inmet.com by sw-eng.falls-church.va.us (8.6.11/) id QAA13786; Fri, 14 Jul 1995 16:00:24 GMT Received: from houdini.camb.inmet.com.i2ada by dsd.camb.inmet.com (4.1/SMI-4.1) id AA08782; Fri, 14 Jul 95 11:58:53 EDT Date: Fri, 14 Jul 95 11:58:53 EDT From: stt@dsd.camb.inmet.com (Tucker Taft) Message-Id: <9507141558.AA08782@dsd.camb.inmet.com> To: ada-comment@sw-eng.falls-church.va.us, mksmith@cli.com Subject: Re: String literal constraint ramification 4.2(11.a) seems bogus. !topic String literal constraint ramification seems bogus. !reference RM95-4.2(11.a) !reference 95-5223.a Michael K. Smith 95-07-14 !from Tucker Taft 95-07-14 <> !discussion > 4.2 (11) states; > > For the evaluation of a string_literal of type T, a check is made that > the value of each character of the string_literal belongs to the > component subtype of T. ... The exception > Constraint_Error is raised if either of these checks fails. > > (11.a) RAMIFICATION: The checks on the characters need not involve more > than two checks altogether, since one need only check the characters of > the string with the lowest and highest position numbers against the range > of the component subtype. > > I don't believe the ramification (or I don't understand it) because > > package t138 is > type Roman_Digit is ('C', 'D', 'I', 'L', 'M', 'V', 'X'); > type Roman_Date is array(positive range <>) of Roman_Digit; > x : Roman_Date := "CWX"; > end; This is illegal, since 'W' is not a character literal of the type. For this legality check, you definitely must look at every character of the string. However, this ramification is talking about the run-time check required, when the component subtype of a string type is a constrained subtype of some character type. For example: subtype Some_Digits is Roman_Digit range F(1) .. G(2); type Some_Date is array(Positive range <>) of Some_Digit; y : Some_Date := "MMVIII"; Even though we don't statically know the values returned by F(1) and G(2), we don't have to make 6 run-time checks to make sure all characters of the string are within Some_Digits'Range. Instead, we take the max and min position numbers of characters in the string -- V has the max position number (Roman_Digit'Pos('V') = 5), and I has the min position number (Roman_Digit'Pos('I') = 2), and all we need to do at run-time is see whether Some_Digits'Last >= 'V' and Some_Digits'First <= 'I'. > Michael K. Smith > Computational Logic Inc. [http://www.cli.com/] > Austin, TX -Tuck