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

"Mike Silva" <mjsilva@jps.net> writes:

> 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.
> 

You're right, of course. I was just thinking about the wrap from 0 to 65535.

> 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
> 
> 
> 
> 

I suppose you could make the routine generic? Then it will work if
NUM_ELMENTS is known at compile time.

-- 
E pluribus Unix




  parent reply	other threads:[~1999-04-08  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 ` David C. Hoos, Sr.
1999-04-06  0:00   ` Mike Silva
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
1999-04-07  0:00             ` Stephen Leake
1999-04-08  0:00             ` Ole-Hjalmar Kristensen [this message]
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-05  0:00 ` Marin David Condic
replies disabled

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