delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/07/04:42:38

Message-Id: <200007070842.LAA01023@mailgw1.netvision.net.il>
Date: Fri, 07 Jul 2000 11:42:36 +0200
To: Harald Jeszenszky <harald DOT jeszenszky AT oeaw DOT ac DOT at>
X-Mailer: Emacs 20.6 (via feedmail 8.2.emacs20_6 I) and Blat ver 1.8.5b
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
CC: djgpp AT delorie DOT com
In-reply-to: <396583E8.C09E13E2@oeaw.ac.at> (message from Harald Jeszenszky on
Fri, 07 Jul 2000 09:16:56 +0200)
Subject: Re: Arbitrary variable order ?
References: <396433B4 DOT 4370ADC2 AT oeaw DOT ac DOT at> <396583E8 DOT C09E13E2 AT oeaw DOT ac DOT at>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> From: Harald Jeszenszky <harald DOT jeszenszky AT oeaw DOT ac DOT at>
> Newsgroups: comp.os.msdos.djgpp
> Date: Fri, 07 Jul 2000 09:16:56 +0200
> 
> Thanks for all your suggestions. I am aware of the problem with this
> 'poor' programming style. The software has been written for a runtime
> system with C environment and is povided as is. There are about 150 (!)
> variables affected by this statement. Because of the lack of code space
> the program can't be extended (which will be the case when replacing the
> copy statement by assignments). Using an array or structure means to
> change all the variable references and is not feasible.

You can define an array and use the preprocessor magic to work around
the code space limitations.  For example:

    static unsigned char var_array[2000];

    #define var1 var_array[0];
    #define var2 var_array[3];  /* assuming var1 was an int */
    #define var2 var_array[6];  /* assuming var2 was a 16-bit short */
    ...

If you pay attention to alignment, the only price you pay is that the
variables are now static instead of automatic.  (That, and lots of
manual labor to write these lines of #define's.)  But you don't pay
anything in terms of the code space for this, since the preprocessor
doesn't produce any code.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019