home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Supreme Volume 6 #1
/
swsii.zip
/
swsii
/
215
/
DDJ9301.ZIP
/
PORT.ASC
< prev
next >
Wrap
Text File
|
1992-12-08
|
2KB
|
120 lines
_PORTING FROM 16-BIT TO 32-BIT EXTENDED DOS_
by Joe Huffman
Figure 1:
/***** Use shifts and logical operators to speed up the binary search routine.
Avoids the use of slow divides. *****/
unsigned int binary_search(const char **array_p, const char *find_p, int size)
{
unsigned int mask = 1 << 15; /* Assumes 16-bit integers! */
unsigned int index = mask;
int comp_val = 1; /* Initialize the compare value to decrease */
/* the index until index < size. */
while(index >= size ||
mask && (comp_val = strcmp(array_p[index], find_p)) != 0)
{
if(comp_val > 0) /* If the value is too high, clear this bit. */
index ^= mask;
mask >>= 1;
index |= mask;
}
return index;
}
Figure 2:
struct fig_2a
{
char c;
int i;
};
struct fig_2b
{
char c1, c2;
int i;
};
Compiler sizeof(struct fig_2a) sizeof(struct fig_2b)
Borland C/C++ 3.1 all models 3 4
Microsoft C/C++ 7.0 all models 4 4
Watcom 386/9.0 (32-bit code) 5 6
Zortech 3.0 T,S,C,M,L,Z models 4 4
Zortech 3.0 X model 8 8
Figure 3:
struct fig_3a
{
char c1;
int i1;
char c2;
int i2;
char c3;
int i3;
char c4;
};
struct fig_3b
{
char c1;
char c2;
char c3;
char c4;
int i1;
int i2;
int i3;
};
Compiler sizeof(struct fig_3a) sizeof(struct fig_3b)
Borland C/C++ 3.1 all models 10 10
Microsoft C/C++ 7.0 all models 14 10
Watcom 386/9.0 (32-bit code) 16 16
Zortech 3.0 T,S,C,M,L,Z models 14 10
Zortech 3.0 X model 28 16
Figure 4:
struct attribute
{
char fg_color, bg_color;
};
Figure 5:
#define BYTES_PER_ATTR 2
#define TABLE_SIZE 10
struct attribute attr_table[TABLE_SIZE];
void read_attr_table(FILE *fp)
{
int i;
char *p = (char *)&attr_table[0];
for(i = 0; i < TABLE_SIZE; i++)
{
int j;
for(j = 0; j < BYTES_PER_ATTR; j++)
{
int tmp;
scanf(fp, "%d", &tmp);
*p++ = tmp;
}
}
}