From: Robert A Duff <bobduff@world.std.com>
Subject: Re: Static assertions
Date: Fri, 18 May 2001 21:27:24 GMT
Date: 2001-05-18T21:27:24+00:00 [thread overview]
Message-ID: <wccwv7e5ow3.fsf@world.std.com> (raw)
In-Reply-To: 3B054ABE.9B3DA459@boeing.com
Jeffrey Carter <jeffrey.carter@boeing.com> writes:
> Isn't that "Danger, Will Robinson"?
Probably.
> I certainly agree with this advice. One thing that always stopped me
> short in my tracks was code with constructs such
>
> ... + My_Type (3) - ...
>
> apparently written by people who thought that "3" has type Integer (or
> perhaps used a compiler with that "feature").
Well, there *are* languages where "3" is an int, and "3L" is
a long (or even "3l"). Yuck.
> However, is there any reason to write
>
> Assert_1 : constant := Boolean'Pos (Assert'(Integer'Size = 73) );
>
> rather than
>
> Assert_1 : constant Assert := Integer'Size = 73;
>
> ? Are there compilers that won't check this during compilation?
I think the former is required to get a compile time error,
whereas the latter is merely allowed to produce a warning.
The subtle difference is that the former has a static expression
raising an exception, whereas the latter has a perfectly good
static expression, but the assignment will raise an exception.
I'm too lazy to look it up in the RM, so I could be mistaken...
Furthermore, if the second one doesn't get detected at compile time, it
might not get detected at all. I believe 11.6 allows the compiler to
"optimize away" the constraint check, so it never happens at run time.
(I'm assuming Assert_1 is a dead variable.)
- Bob
next prev parent reply other threads:[~2001-05-18 21:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-05-18 5:34 Static assertions Christoph Grein
2001-05-18 13:38 ` Robert A Duff
2001-05-18 16:15 ` Jeffrey Carter
2001-05-18 17:25 ` Ted Dennison
2001-05-18 21:27 ` Robert A Duff [this message]
2001-05-18 22:46 ` Jeffrey Carter
2001-05-19 22:53 ` Robert A Duff
-- strict thread matches above, loose matches on Subject: below --
2001-05-17 15:07 Jean-Pierre Rosen
2001-05-17 17:44 ` Jeffrey Carter
2001-05-17 19:09 ` Marin David Condic
2001-05-17 22:34 ` Jeffrey Carter
2001-05-18 13:39 ` Marin David Condic
2001-05-18 1:23 ` Robert A Duff
2001-05-19 7:40 ` David Kristola
2001-05-19 22:56 ` Robert A Duff
2001-05-19 8:36 ` Aaro Koskinen
2001-05-21 7:50 ` Jean-Pierre Rosen
2001-06-12 3:59 ` David Thompson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox