Languages and Scripting

How to pack structures on HPUX PA RISC64

 
MasthanD
Occasional Contributor

How to pack structures on HPUX PA RISC64

Dear All,

For understanding the PACKED STRUCTURES on HPUX, I wrote the below program and executed on HPUX PA RISC 64 11.31 machine.

bash-4.3$ cat abc.c
#include <stdio.h>

/* BEGIN THE PACK */
#pragma pack(1)
typedef union
{
char a[6];
int ab[1];
} abc_packed;
#pragma pack()
/* END THE PACK */

typedef union
{
char a[6];
int ab[1];
} abc_unpacked;

main()
{
printf("sizeof(abc_packed) is: %d sizeof(int) is %d sizeof(char) is %d\n",
sizeof(abc_packed), sizeof(int), sizeof(char));

printf("sizeof(abc_unpacked) is: %d\n ", sizeof(abc_unpacked));
}
bash-4.3$

 

bash-4.3$ ./a.out
sizeof(abc_packed) is: 8 sizeof(int) is 4 sizeof(char) is 1
sizeof(abc_unpacked) is: 8
bash-4.3$

 

Interstingly the size of both packed and  unpacked unions is same.

On other Operating System, for packed unions the size is 6 bytes for unpacked unions it is 8 bytes.

For me it looks like, In the above code, the preprocessor macro "#pragma pack(1)" has no effect on HPUX PA RISC64 machine. 

Is there any other option for packing structures/unions on HPUX PA RISC?

 

Thanks,

 

1 REPLY 1
Steven Schweda
Honored Contributor

Re: How to pack structures on HPUX PA RISC64

> [...] executed on HPUX PA RISC 64 11.31 machine.

> On other Operating System, [...]

   But before you executed anything, you compiled it first, right?
Using what?  This is less a hardware or OS question than it is a
compiler question.

> Is there any other option for packing structures/unions on HPUX PA
> RISC?

   If you're using some (intentionally crippled) "bundled" compiler,
then you might try using some real compiler.

   Your bundled compiler might be better than mine, but perhaps not much
better.   Of course, with my weak psychic powers, I can't see your work.

dy $ uname -a
HP-UX dy B.11.11 U 9000/785 2012616114 unlimited-user license

dy $ cc -o pack_cc pack.c
(Bundled) cc: "pack.c", line 4: warning 42: The "PACK" pragma needs an
integer argument.
(Bundled) cc: "pack.c", line 10: warning 42: The "PACK" pragma needs an
integer argument.

dy $ gcc -o pack_gcc pack.c

dy $ ./pack_cc
sizeof(abc_packed) is: 8 sizeof(int) is 4 sizeof(char) is 1
sizeof(abc_unpacked) is: 8

dy $ ./pack_gcc
sizeof(abc_packed) is: 6 sizeof(int) is 4 sizeof(char) is 1
sizeof(abc_unpacked) is: 8

   There's much to be said for naturally aligned structures, I claim.