Thread View: comp.lang.modula2
5 messages
5 total messages
Started by Eric Obermuhlner
Fri, 15 Mar 1996 00:06
constant tables?
Author: Eric Obermuhlner
Date: Fri, 15 Mar 1996 00:06
Date: Fri, 15 Mar 1996 00:06
17 lines
916 bytes
916 bytes
How do I make constant tables? I write code for an embedded system. Lookup tables in ROM are a pretty useful thing and I just couldn't find a way to do it. Did I miss something? Something like [BEGIN EXAMPLE] VAR myTable : ARRAY [0..9] OF CARDINAL = [0, 6, 2, 5, 1, 3, 4, 9, 8, 7]; [END EXAMPLE] +-------------------------------------------------------------+ |Eric Obermuhlner |erico@g-wiz.com | Microsoft free since 1967 +-------------------------------------------------------------+
Re: constant tables?
Author: frank
Date: Fri, 15 Mar 1996 07:44
Date: Fri, 15 Mar 1996 07:44
39 lines
1465 bytes
1465 bytes
erico@cnmat.berkeley.edu (Eric Obermuhlner) wrote:
> How do I make constant tables?
>
> I write code for an embedded system. Lookup tables in ROM are a
pretty useful thing and I just couldn't find a way to do it.
>
> Did I miss something?
>
> Something like
> [BEGIN EXAMPLE]
> VAR
> myTable : ARRAY [0..9] OF CARDINAL = [0, 6, 2, 5, 1, 3, 4, 9,
8, 7];
> [END EXAMPLE]
Hmm, havn't been doing much MODULA programming lately, but from
what I take from the MODULA standard, it would be something like:
MODULE example;
TYPE
CA = ARRAY [0..9] OF CARDINAL;
CONST
myTable = CA({0, 6, 2, 5, 1, 3, 4, 9, 8, 7});
...
though I can't garantee that the braces ({}) are correct.
-Robert
--
Institut fuer Informatik tel +41 (0)61 321 99 67
Universitaet Basel fax. +41 (0)61 321 99 15
Robert Frank
Mittlere Strasse 142 rfc822: frank@ifi.unibas.ch (NeXT,MIME mail
ok)
CH-4056 Basel X400:
S=frank;OU=ifi;O=unibas;P=switch;A=arcom;C=ch
Switzerland
Re: constant tables?
Author: "Mark Morgan Lloyd "
Date: Fri, 15 Mar 1996 13:34
Date: Fri, 15 Mar 1996 13:34
32 lines
1344 bytes
1344 bytes
Please try to keep your lines a bit shorter :-) > How do I make constant tables? > > I write code for an embedded system. Lookup tables in ROM are a pretty > useful thing and I just couldn't find a way to do it. Depending on your compiler, you may find the literal data being put in an unexpected segment, and then copied to a literal constant. It is sometimes easier to put this sort of thing into a fixed location in memory, accessed by an absolute variable. > Did I miss something? > > Something like > [BEGIN EXAMPLE] > VAR > myTable : ARRAY [0..9] OF CARDINAL = [0, 6, 2, 5, 1, 3, 4, 9, 8, 7]; > [END EXAMPLE] Depends very much on the compiler. Under TopSpeed (which we use for embedded '386): TYPE tableType= ARRAY[0..9] OF CARDINAL; CONST myTable= tableType(0, 6, 2, 5, 1, 3, 4, 9, 8, 7); Mark Morgan Lloyd mark_tbu@cix.compulink.co.uk [Opinions above are the author's, not those of his employers or colleagues]
Re: constant tables?
Author: Bill Seurer
Date: Mon, 18 Mar 1996 15:37
Date: Mon, 18 Mar 1996 15:37
8 lines
776 bytes
776 bytes
Constant tables were non-standard in earlier versions of Modula-2. Some allowed it (like TopSpeed) anyway. The new standard allows it but I don't know of any compilers. -- - Bill Seurer ID Tools and Compiler Development IBM Rochester, MN Business: BillSeurer@vnet.ibm.com Home: BillSeurer@aol.com
Re: constant tables?
Author: John Gough
Date: Tue, 19 Mar 1996 04:49
Date: Tue, 19 Mar 1996 04:49
22 lines
1280 bytes
1280 bytes
Bill Seurer wrote:
>
> Constant tables were non-standard in earlier versions of Modula-2. Some
> allowed it (like TopSpeed) anyway.
>
> The new standard allows it but I don't know of any compilers.
> --
>
> - Bill Seurer ID Tools and Compiler Development IBM Rochester, MN
> Business: BillSeurer@vnet.ibm.com Home: BillSeurer@aol.com
Sure, all the native code versions of gpm allow this.
Furthermore, in code (as opposed to constant declarations)
you can write
blah := MyType{exp1, exp2, ..., expN};
where exp1, exp2 are any expressions. The compiler extracts
the constant parts at compile time, and fills in the variable
parts at runtime.
John Gough
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads