comp.lang.ada
 help / color / mirror / Atom feed
* How to get a compilation error
@ 2001-11-15 14:16 Wilhelm Spickermann
  2001-11-15 15:06 ` Martin Dowie
  0 siblings, 1 reply; 13+ messages in thread
From: Wilhelm Spickermann @ 2001-11-15 14:16 UTC (permalink / raw)
  To: comp.lang.ada

Hi,

I would like to get a compilation *error*, if some compile time 
constant is not suitable for the algorithm in use. Example:

Chunk_Bits : constant :=
  Integer'Min (32, System.Max_Binary_Modulus / 2);
type Check is (Checkitem1, Checkitem2);
for Check'SIZE use 1 - Integer'MIN (96 mod Chunk_Bits, 1);

The last two lines result in a compilation error, if and (I 
hope) only if 96 is not a multiple of Chunk_Bits. That´s what I 
want -- but it´s really ugly. Does anyone have something better?

Wilhelm





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to get a compilation error
  2001-11-15 14:16 Wilhelm Spickermann
@ 2001-11-15 15:06 ` Martin Dowie
  2001-11-15 15:09   ` Jean-Pierre Rosen
  2001-11-15 17:47   ` Wilhelm Spickermann
  0 siblings, 2 replies; 13+ messages in thread
From: Martin Dowie @ 2001-11-15 15:06 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 950 bytes --]

"Wilhelm Spickermann" <wilhelm.spickermann@t-online.de> wrote in message
news:mailman.1005833842.603.comp.lang.ada@ada.eu.org...
Hi,

I would like to get a compilation *error*, if some compile time
constant is not suitable for the algorithm in use. Example:

Chunk_Bits : constant :=
  Integer'Min (32, System.Max_Binary_Modulus / 2);
type Check is (Checkitem1, Checkitem2);
for Check'SIZE use 1 - Integer'MIN (96 mod Chunk_Bits, 1);

The last two lines result in a compilation error, if and (I
hope) only if 96 is not a multiple of Chunk_Bits. That�s what I
want -- but it�s really ugly. Does anyone have something better?


Could try:

   type A_Valid_Range is range 0 .. 0;

   My_Check : constant A_Valid_Range :=
      A_Valid_Range (96 mod (Integer'Min (32, System.Max_Binary_Modulus /
2)));

This will probably raise a warning rather than an error though.
Some compilers will let you specify that warning are to be
treated as errors.






^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to get a compilation error
  2001-11-15 15:06 ` Martin Dowie
@ 2001-11-15 15:09   ` Jean-Pierre Rosen
  2001-11-15 17:38     ` Wilhelm Spickermann
                       ` (2 more replies)
  2001-11-15 17:47   ` Wilhelm Spickermann
  1 sibling, 3 replies; 13+ messages in thread
From: Jean-Pierre Rosen @ 2001-11-15 15:09 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1491 bytes --]


"Martin Dowie" <martin.dowie@nospam.baesystems.com> a �crit dans le message news: 3bf3d68c$1@pull.gecm.com...
> "Wilhelm Spickermann" <wilhelm.spickermann@t-online.de> wrote in message
> news:mailman.1005833842.603.comp.lang.ada@ada.eu.org...
> Hi,
>
> I would like to get a compilation *error*, if some compile time
> constant is not suitable for the algorithm in use. Example:
>
> Chunk_Bits : constant :=
>   Integer'Min (32, System.Max_Binary_Modulus / 2);
> type Check is (Checkitem1, Checkitem2);
> for Check'SIZE use 1 - Integer'MIN (96 mod Chunk_Bits, 1);
>
> The last two lines result in a compilation error, if and (I
> hope) only if 96 is not a multiple of Chunk_Bits. That�s what I
> want -- but it�s really ugly. Does anyone have something better?
>
>
> Could try:
>
>    type A_Valid_Range is range 0 .. 0;
>
>    My_Check : constant A_Valid_Range :=
>       A_Valid_Range (96 mod (Integer'Min (32, System.Max_Binary_Modulus /
> 2)));
>
> This will probably raise a warning rather than an error though.
> Some compilers will let you specify that warning are to be
> treated as errors.
To get an error, do the following:
subtype Assert is boolean range True..True;
Check : constant := Assert'Pos(96 rem Chunk_Bits = 0)

Since Check is a named number, an invalid value will result in a compile time error (new in 95).

--
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to get a compilation error
  2001-11-15 15:09   ` Jean-Pierre Rosen
@ 2001-11-15 17:38     ` Wilhelm Spickermann
  2001-11-16  8:19       ` Jean-Pierre Rosen
  2001-11-15 23:49     ` martin.m.dowie
  2001-11-16  9:05     ` Wilhelm Spickermann
  2 siblings, 1 reply; 13+ messages in thread
From: Wilhelm Spickermann @ 2001-11-15 17:38 UTC (permalink / raw)
  To: comp.lang.ada



--On Donnerstag, November 15, 2001 16:09:50 +0100 Jean-Pierre 
Rosen <rosen@adalog.fr> wrote:

> To get an error, do the following:
> subtype Assert is boolean range True..True;
> Check : constant := Assert'Pos(96 rem Chunk_Bits = 0)
>
> Since Check is a named number, an invalid value will result in
> a compile time error (new in 95).

Hmm, I didn´t get a compilation error with gnat and I think 
thats correct. 0 is a valid value for Check and False is a valid 
parameter for Assert´POS as it takes Assert´BASE parameters 
according to ARM 3.5.5(3).

Wilhelm




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to get a compilation error
  2001-11-15 15:06 ` Martin Dowie
  2001-11-15 15:09   ` Jean-Pierre Rosen
@ 2001-11-15 17:47   ` Wilhelm Spickermann
  1 sibling, 0 replies; 13+ messages in thread
From: Wilhelm Spickermann @ 2001-11-15 17:47 UTC (permalink / raw)
  To: comp.lang.ada



--On Donnerstag, November 15, 2001 15:06:41 +0000 Martin Dowie 
<martin.dowie@nospam.baesystems.com> wrote:

> Could try:
>
>    type A_Valid_Range is range 0 .. 0;
>
>    My_Check : constant A_Valid_Range :=
>       A_Valid_Range (96 mod (Integer'Min (32,
> System.Max_Binary_Modulus / 2)));
>
> This will probably raise a warning rather than an error though.
> Some compilers will let you specify that warning are to be
> treated as errors.

Yes, thank you. But it would be nice to be sure, that the guys 
using a package cannot get it to work, if it would fail in their 
environment.

Wilhelm




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to get a compilation error
  2001-11-15 15:09   ` Jean-Pierre Rosen
  2001-11-15 17:38     ` Wilhelm Spickermann
@ 2001-11-15 23:49     ` martin.m.dowie
  2001-11-16  9:05     ` Wilhelm Spickermann
  2 siblings, 0 replies; 13+ messages in thread
From: martin.m.dowie @ 2001-11-15 23:49 UTC (permalink / raw)


> > Could try:
> >
> >    type A_Valid_Range is range 0 .. 0;
> >
> >    My_Check : constant A_Valid_Range :=
> >       A_Valid_Range (96 mod (Integer'Min (32, System.Max_Binary_Modulus
/
> > 2)));
> >
> > This will probably raise a warning rather than an error though.
> > Some compilers will let you specify that warning are to be
> > treated as errors.
> To get an error, do the following:
> subtype Assert is boolean range True..True;
> Check : constant := Assert'Pos(96 rem Chunk_Bits = 0)
>
> Since Check is a named number, an invalid value will result in a compile
time error (new in 95).

Ooohhh! That's good!!!

Don't you just love this language!





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to get a compilation error
  2001-11-15 17:38     ` Wilhelm Spickermann
@ 2001-11-16  8:19       ` Jean-Pierre Rosen
  2001-11-16  9:44         ` Wilhelm Spickermann
  2001-11-16 10:22         ` Pi
  0 siblings, 2 replies; 13+ messages in thread
From: Jean-Pierre Rosen @ 2001-11-16  8:19 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 852 bytes --]


"Wilhelm Spickermann" <wilhelm.spickermann@t-online.de> a �crit dans le message news:
mailman.1005881899.15799.comp.lang.ada@ada.eu.org...
>> To get an error, do the following:
>> subtype Assert is boolean range True..True;
>> Check : constant := Assert'Pos(96 rem Chunk_Bits = 0)
>>
>> Since Check is a named number, an invalid value will result in
>> a compile time error (new in 95).
>
>Hmm, I didn�t get a compilation error with gnat and I think
>thats correct. 0 is a valid value for Check and False is a valid
>parameter for Assert�POS as it takes Assert�BASE parameters
>according to ARM 3.5.5(3).
That's right... try:
Check : constant := Assert'Pos(Assert(96 rem Chunk_Bits = 0))


--
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to get a compilation error
@ 2001-11-16  8:23 Gautier Write-only-address
  0 siblings, 0 replies; 13+ messages in thread
From: Gautier Write-only-address @ 2001-11-16  8:23 UTC (permalink / raw)
  To: comp.lang.ada

>From: "Jean-Pierre Rosen" <rosen@adalog.fr>

>To get an error, do the following:
>subtype Assert is boolean range True..True;
>Check : constant := Assert'Pos(96 rem Chunk_Bits = 0)
>
>Since Check is a named number, an invalid value will result in a compile 
>time error (new in 95).

Interesting to observe that neither GNAT 3.13p nor OA 7.2.1
says anything against
------------------------------------------------------
procedure xxx is

  subtype Assert is Boolean range True..True;
  Check1 : constant := Assert'Pos(True) ;
  Check2 : constant := Assert'Pos(False) ;

begin
  null;
end;
------------------------------------------------------
;-)
______________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/e3d.htm

NB: Do not answer to sender address, visit the Web site!
    Ne r�pondez pas � l'exp�diteur, visitez le site ouaibe!


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to get a compilation error
  2001-11-15 15:09   ` Jean-Pierre Rosen
  2001-11-15 17:38     ` Wilhelm Spickermann
  2001-11-15 23:49     ` martin.m.dowie
@ 2001-11-16  9:05     ` Wilhelm Spickermann
  2 siblings, 0 replies; 13+ messages in thread
From: Wilhelm Spickermann @ 2001-11-16  9:05 UTC (permalink / raw)
  To: comp.lang.ada



--On Donnerstag, November 15, 2001 16:09:50 +0100 Jean-Pierre 
Rosen <rosen@adalog.fr> wrote:

> Since Check is a named number, an invalid value will result in
> a compile time error (new in 95).

I´ve used this idea to make my solution less ugly. Instead of 
writing:

type Check is (Checkitem1, Checkitem2);
for Check'SIZE use 1 - Integer'MIN (96 mod Chunk_Bits, 1);

I´ve used now:

Check : constant := 1 / (1 - Integer'MIN (96 mod Chunk_Bits, 
1));

Thanks
  Wilhelm




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to get a compilation error
  2001-11-16  8:19       ` Jean-Pierre Rosen
@ 2001-11-16  9:44         ` Wilhelm Spickermann
  2001-11-16 10:22         ` Pi
  1 sibling, 0 replies; 13+ messages in thread
From: Wilhelm Spickermann @ 2001-11-16  9:44 UTC (permalink / raw)
  To: comp.lang.ada



--On Freitag, November 16, 2001 09:19:11 +0100 Jean-Pierre Rosen 
<rosen@adalog.fr> wrote:

> That's right... try:
> Check : constant := Assert'Pos(Assert(96 rem Chunk_Bits = 0))

Thats it! Thank You.
  Wilhelm

PS: I had tried this after Your first mail and thought it 
wouldn´t work, because gnat told me "non-static expression used 
in number declaration". Well, I should have read all the 3 error 
messages from gnat: it was only a follow-up-error of "static 
expression raises ""Constraint_Error""".




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to get a compilation error
  2001-11-16  8:19       ` Jean-Pierre Rosen
  2001-11-16  9:44         ` Wilhelm Spickermann
@ 2001-11-16 10:22         ` Pi
  2001-11-16 17:27           ` Wilhelm Spickermann
  1 sibling, 1 reply; 13+ messages in thread
From: Pi @ 2001-11-16 10:22 UTC (permalink / raw)


Jean-Pierre Rosen wrote :

> 
> "Wilhelm Spickermann" <wilhelm.spickermann@t-online.de> a �crit dans le
> message news: mailman.1005881899.15799.comp.lang.ada@ada.eu.org...
> >> To get an error, do the following:
> >> subtype Assert is boolean range True..True;
> >> Check : constant := Assert'Pos(96 rem Chunk_Bits = 0)
> >>
> >> Since Check is a named number, an invalid value will result in
> >> a compile time error (new in 95).
> >
> >Hmm, I didn�t get a compilation error with gnat and I think
> >thats correct. 0 is a valid value for Check and False is a valid
> >parameter for Assert�POS as it takes Assert�BASE parameters
> >according to ARM 3.5.5(3).
> That's right... try:
> Check : constant := Assert'Pos(Assert(96 rem Chunk_Bits = 0))
> 

or

Check : constant Boolean := Boolean'Pred(96 rem Chunk_Bits = 0);

or 

Check : constant := Boolean'Pos(Boolean'Pred(96 rem Chunk_Bits = 0));

no need for an Assert-subtype ;-)
Only that Check will always be false when it compiles.

TMTOWTDI

-- 
3,14159265359




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to get a compilation error
  2001-11-16 10:22         ` Pi
@ 2001-11-16 17:27           ` Wilhelm Spickermann
  0 siblings, 0 replies; 13+ messages in thread
From: Wilhelm Spickermann @ 2001-11-16 17:27 UTC (permalink / raw)
  To: comp.lang.ada



--On Freitag, November 16, 2001 05:22:34 -0500 Pi 
<pi3_1415926536@yahoo.ca> wrote:

> Check : constant Boolean := Boolean'Pred(96 rem Chunk_Bits =
> 0);

Looks really good!

Thanks
 Wilhelm

> --
> 3,14159265359

--
13h25m11.6s,-11°09´41.0"




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to get a compilation error
       [not found] <mailman.1005975714.13778.comp.lang.ada@ada.eu.org>
@ 2001-11-17 11:32 ` Preben Randhol
  0 siblings, 0 replies; 13+ messages in thread
From: Preben Randhol @ 2001-11-17 11:32 UTC (permalink / raw)


On Fri, 16 Nov 2001 21:39:53 -0800, R. Tim Coslet wrote:
>> This message is in MIME format. Since your mail reader does not understand
> this format, some or all of this message may not be legible.
> 
> --Boundary_(ID_jt2nYvWuvjIUcJVM7XMYIw)
> Content-type: text/plain; charset=ISO-8859-1
> Content-transfer-encoding: quoted-printable
> 
> The problem with this is it allocates a constant.
> 
> The named number solution allocates no memory for a constant in the
> executable.
> 
> --=20
>        R. Tim Coslet
>        r_tim_coslet@pacbell.net


Turn off HTML when you post to usenet.

Preben
--
                 �For me, Ada95 puts back the joy in programming.�



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2001-11-17 11:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-16  8:23 How to get a compilation error Gautier Write-only-address
     [not found] <mailman.1005975714.13778.comp.lang.ada@ada.eu.org>
2001-11-17 11:32 ` Preben Randhol
  -- strict thread matches above, loose matches on Subject: below --
2001-11-15 14:16 Wilhelm Spickermann
2001-11-15 15:06 ` Martin Dowie
2001-11-15 15:09   ` Jean-Pierre Rosen
2001-11-15 17:38     ` Wilhelm Spickermann
2001-11-16  8:19       ` Jean-Pierre Rosen
2001-11-16  9:44         ` Wilhelm Spickermann
2001-11-16 10:22         ` Pi
2001-11-16 17:27           ` Wilhelm Spickermann
2001-11-15 23:49     ` martin.m.dowie
2001-11-16  9:05     ` Wilhelm Spickermann
2001-11-15 17:47   ` Wilhelm Spickermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox