Mail Archives: djgpp/2000/01/22/16:24:58
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 -