Operating System - HP-UX
1836444 Members
2418 Online
110100 Solutions
New Discussion

Re: C typecast - difference between HPUX on IPF vs PA-RISC

 
Yves Lagacé
New Member

C typecast - difference between HPUX on IPF vs PA-RISC

Here's a little C program:

#include

int main (int argc, char *argv [])
{
struct a bob
{
unsigned int var1 : 25 ; /* 1..24 */
unsigned int var2 : 2 ; /* 25..26 */
insigned int var3 : 5 ; /* 27..31 */
} ;

bob.var1 = 1 ;
bob.var2 = 0 ;
bob.var3 = 1 ;

printf ("var1 %d, var2 %d, bob %d\n",
bob.var1,
bob.bar2,
bob ) ;

printf ("var1 %d, var2 %d, bob %d\n",
bob.var1,
bob.bar2,
*((long *) &bob) ) ; /* typecast */

return (0) ;
}

On PA-RISC, the output is :
var1 1, var2 0, bob 129
var1 1, var2 0, bob 129

On Itaniun, I have the following output
var1 1, var2 0, bob 0
var1 1, var2 0, bob 129

Why is there a difference? I am missing a compilation switch?
1 REPLY 1
Mike Stroyan
Honored Contributor

Re: C typecast - difference between HPUX on IPF vs PA-RISC

There is a difference because your code is passing a passing a struct by value, but telling printf that it got an int by value. That is broken. The results will depend on the details of the parameter passing conventions. They may also be affected by uninitialized register and stack values, since the called function is likely to look at locations that the caller did not set.

The calling conventions are documented in

"32-bit pa-risc run-time architecture"-
http://devresource.hp.com/drc/STK/docs/archive/rad_10_20.pdf

"64-Bit run-time architecture for PA-RISC 2.0"-
http://devresource.hp.com/drc/STK/docs/archive/pa64rt.pdf

"Itanium Software Conventions and Runtime Architecture"-
http://devresource.hp.com/drc/resources/ia64rt-12-gen.pdf