delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/22/16:24:58

Message-ID: <388A0530.DF2B2F31@ou.edu>
From: David Cleaver <davidis AT ou DOT edu>
X-Mailer: Mozilla 4.7 [en] (Win98; I)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Length of Chars...
References: <3888ED7B DOT DF52FEB2 AT ou DOT edu> <38896068 DOT 8C5927C0 AT is DOT elta DOT co DOT il>
Lines: 48
Date: Sat, 22 Jan 2000 13:29:52 -0600
NNTP-Posting-Host: 129.15.140.115
X-Complaints-To: usenet AT ou DOT edu
X-Trace: news.ou.edu 948569321 129.15.140.115 (Sat, 22 Jan 2000 13:28:41 CST)
NNTP-Posting-Date: Sat, 22 Jan 2000 13:28:41 CST
Organization: The University of Oklahoma
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com


Eli Zaretskii wrote:
 
> > Ok, well, the real problem is that I'm writing a program that is very
> > dependent on the char data type being 8-bits.
> 
> I'm not sure I understand the context (so please feel free to explain more),
> but the usual way to handle these situations is to define a data type (with
> `typedef') that is as wide as you want, and then use it for those variables
> which need to be of that width.
>
> > I think this would help out
> > alot so that programs could be written more with storage in mind.
> 
> Keep in mind that many programs don't care much about the storage in many
> cases.  For example, when you code a simple for loop which is going to be
> executed a few dozen times, you want the fastest data type, no matter what
> the storage is.


OK, I'll explain a little 'bit' more.  :)  I'm writing a program to
factor numbers, hopefully, very quickly.  Now, in order to do this I
have created a bunch of two dimensional arrays whose elements only
consist of zero's and one's.  Since this is the case, I decided to
reduce the size of the array from using an int for each zero or one, and
have packed all the zero's and one's into unsigned char's.  As you can
see, this greatly reduced the amount of storage needed for these
tables.  However, if the char type ever increases in size, my tables
wouldn't be as tighly packed as possible, so I wanted to know if it was
ever going to change.

Eli, what did you mean by using the "fastest data type" in a for loop? 
What is the fastest data type that you are refering to here?  I wouldn't
mind being able to speed up my program a bit more.

Also, is it ok to store unsigned chars in hex form?  I'll give an
example below:

unsigned char array1[3][3] = {{0x2a, 0xf4, 0x08},
                              {0x96, 0xa5, 0x7c},
                              {0x8e, 0x59, 0x8b});

Is this ok, or will the compiler complain, or will I even still be able
to access it like I normally would?  Again, thank you(everyone) for
helping with all my questions.

-David C.

- Raw text -


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