Using unsigned char instead of int?
bxpfac at umiami.ir.miami.edu
bxpfac at umiami.ir.miami.edu
Wed Dec 26 14:08:00 AEST 1990
From: Bimal (devebw9f at miavax.ir.miami.edu)
In one of my applications, most of my integer numbers are small in
magnitude and positive. I am considering using unsigned char in
order to conserve memory space.
Consider the following code fragments:
A. usigned char i;
for (i = 0; i < 100; i++) {
...
B. typedef struct {
unsigned char a;
unsigned char b;
unsigned short c;
} EXAMPLE ;
EXAMPLE p;
Questions:
1. In example A above, is the use of unsigned char any faster compared to
using short or int? Any drawbacks? (Incidentally, I will be using
either the gcc compiler or the turboc compiler for this).
2. How would one go about reading and writing the struct above using
fprintf and fscanf?
To elaborate further:
fprintf (fd, "%? %? %hu\n", p.a, p.b, p.c);
fscanf (fd, "%? %? %hu" , &p.a, &p.b, &p.c);
/\
what should I use here | ?
Thanks for your response.
Bimal
More information about the Comp.lang.c
mailing list