home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
utilities
/
utilss
/
sprtools
/
unix
/
endian_c
next >
Wrap
Text File
|
1994-07-18
|
1KB
|
68 lines
/************************************************************************
* *
* endian.c *
* *
* test of endian and word alignment/structure padding *
* *
* Version 0.10 (15-Oct-1993) *
* *
************************************************************************/
#include <stdio.h>
typedef struct
{
int dword1;
short word1;
short word2;
short word3;
int dword2;
} align_str;
typedef struct
{
short word1;
char byte;
short word2;
} word_str;
typedef struct
{
int dword1;
char byte;
int dword2;
} dword_str;
int main(void)
{
char array[4];
align_str align;
word_str wtest;
dword_str dwtest;
int word_align;
int dword_align;
int word_pad;
int dword_pad;
array[0] = 0x12;
array[1] = 0x34;
array[2] = 0x56;
array[3] = 0x78;
if(*((int*)array) == 0x12345678)
printf("endian : big (0x%8X)\n",*((int*)array));
else
printf("endian : little (0x%8X)\n",*((int*)array));
word_align = (int)&align.word2 - (int)&align.word1;
word_pad = (int)&wtest.word2 - (int)&wtest.word1 -2;
dword_align = (int)&align.dword2 - (int)&align.word3;
dword_pad = (int)&dwtest.dword2 - (int)&dwtest.dword1 -4;
printf("word alignment : %d\n",word_align);
printf("word padding : %d\n",word_pad);
printf("dword alignment: %d\n",dword_align);
printf("dword padding : %d\n",dword_pad);
}