comp.lang.ada
 help / color / mirror / Atom feed
From: "Mike Silva" <mjsilva@jps.net>
Subject: Re: Modular type. What is it and why?
Date: 1999/04/07
Date: 1999-04-07T00:00:00+00:00	[thread overview]
Message-ID: <7eftdm$7rn$1@its.hooked.net> (raw)
In-Reply-To: umqg16cpn3y.fsf@maestro.clustra.com

Ole-Hjalmar Kristensen wrote in message ...
>> but you can't do:
>>
>>  index = ( index - 1 ) % NUM_ELEMENTS;    /* won't handle 0 ->
>> NUM_ELEMENTS - 1 correctly */
>
>Actually, if index is unsigned, then it *will* handle 0 ->
>NUM_ELEMENTS - 1 correctly.

No, if you roll e.g. a 16 bit unsigned int from 0 to 65535, the value 65535
mod N will not in general be N - 1, as we want.  (e.g., by inspection, 65535
mod 10 is 5)
>
>> As Ole-Hjalmar Kristensen commented, the nice Ada solution doesn't work
if
>> NUM_ELEMENTS varies at runtime (at least, it appears that a modular type
>> can't be defined dynamically -- correct?), but that's not the usual case
>> I run across.
>
>Agreed, I just thought I would mention it.

Actually, the more I thought about it the more the static limitation on
modular types makes my idea worthless.  Even if NUM_ELEMENTS is static for
each menu, I'd want the same routine to handle multiple menus, each with a
different NUM_ELEMENTS.  Oh well...

Mike








  reply	other threads:[~1999-04-07  0:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-05  0:00 Modular type. What is it and why? Staffan Dittmer
1999-04-05  0:00 ` Marin David Condic
1999-04-05  0:00 ` David C. Hoos, Sr.
1999-04-06  0:00   ` Mike Silva
1999-04-06  0:00     ` Mike Silva
1999-04-07  0:00       ` Robert Dewar
1999-04-07  0:00         ` Bret
1999-04-11  0:00         ` Florian Weimer
1999-04-06  0:00     ` Ole-Hjalmar Kristensen
1999-04-06  0:00     ` Marin David Condic
1999-04-06  0:00       ` Mike Silva
1999-04-06  0:00         ` bglbv
1999-04-07  0:00         ` Ole-Hjalmar Kristensen
1999-04-07  0:00           ` Mike Silva [this message]
1999-04-07  0:00             ` Stephen Leake
1999-04-08  0:00             ` Ole-Hjalmar Kristensen
replies disabled

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