🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #3174

Re: Modula2 for C programmers?

#3174
From: Eric Obermuhlner
Date: Wed, 24 Jan 1996 01:38
73 lines
3174 bytes
In article <4e1o5v$6i8@seagoon.newcastle.edu.au>, peter@tesla.newcastle.edu.au wrote:

> The obvious question, though, is why you would want to do this.
> Such operations are common in C programming because C lacks
> more elegant ways to get the job done.  In Modula-2, there are
> certainly situations where you want to do weird hardware-dependent
> things and break the type system, but those situations should
> arise only when writing very low-level modules.  In most other
> cases, there's almost always a better way to do the job.

I don't *want* to do this, I didn't find any other way in my case.

<BEGIN WEIRD DESCRIPTION OF MY PROBLEM>
I'm adding Modula code to a project that was 100 percent done in assembler.
I have some global variables that need to be transmitted thru MIDI SYSEX.
I've defined a SYSEX protocoll that allows me to read/write those vars.

SYSEX PARAM_DATA from length val_1 .. val_n SYSEXEND (* sets params to values *)
SYSEX PARAM_REQ from length SYSEXEND (* answered by PARAM_DATA *)

(* Lets assume the vars are: *)
VAR
  alpha : CARDINAL;  (* idx: 0 *)
  beta : CARDINAL;   (* idx: 1 *)
  gamma : CARDINAL;  (* idx: 2 *)

(* My procedure could now look like this *)

PROCEDURE ReadParam( from : CARDINAL, to :CARDINAL);
VAR
  i : CARDINAL;
BEGIN
  FOR i:= from TO to DO
    CASE i OF
    | 0 : alpha := ReadMIDICardinal();
    | 1 : beta := ReadMIDICardinal();
    | 2 : gamma := ReadMIDICardinal();
    (* ... *)
    ELSE
      (* ignore *)
    END; (* CASE i *)
  END; (* FOR i *)
END ReadParam;

(* ... similar for PROCEDURE WriteParam *)

(* or I could use pointer arithmetic to change those values directly. *)

<END WEIRD DESCRIPTION OF MY PROBLEM>

I admit that I don't like the clean Modula solution, because the code will get huge, even if it looks neat. (The variables to change might one day be in the hundreds)

Is there a better way to do this? Maybe like having an array at the same place. (I know, that's C too)

<BEGIN OTHER PROBLEMS>
Are there CONST arrays for ROM tables?
How do I initialize a table with values? (in RAM)
<END OTHER PROBLEMS>

+-------------------------------------------------------------+
|Eric Obermuhlner  
|erico@g-wiz.com
|if (err == err_bounced) send("erico@cnmat.berkeley.edu"); 
+-------------------------------------------------------------+
#include "stddisclaimer"
#include "funnyquotations"
ERROR 10045: FILE "funnyquotations" EXHAUSTED.
OPENING FILE "notsofunnyquotations" INSTEAD.
ERROR -46: FILE "notsofunnyquotations" HAS A BAD BLOCK.
READING "j{Hr4#^_t~~~
ARGH I'M DYING.
dumping core......
(Just kidding)
Technical Details
Message-ID: <erico-2301961638150001@infinitehell.cnmat.berkeley.edu>
Path: arc1-ca.pugleaf.net!infinitehell.cnmat.berkeley.edu!user
References: <erico-1801961940460001@infinitehell.cnmat.berkeley.edu> <4e1o5v$6i8@seagoon.newcastle.edu.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!infinitehell.cnmat.berkeley.edu!user
From: erico@cnmat.berkeley.edu (Eric Obermuhlner)
Newsgroups: comp.lang.modula2
Subject: Re: Modula2 for C programmers?
Date: Tue, 23 Jan 1996 16:38:15 -0900
Organization: G-Wiz
Message-ID: <erico-2301961638150001@infinitehell.cnmat.berkeley.edu>
References: <erico-1801961940460001@infinitehell.cnmat.berkeley.edu> <4e1o5v$6i8@seagoon.newcastle.edu.au>
NNTP-Posting-Host: infinitehell.cnmat.berkeley.edu
X-Newsreader: Value-Added NewsWatcher 2.0b27.1+