Operating System - HP-UX
1825706 Members
3351 Online
109686 Solutions
New Discussion

va_arg() alignment error on HP-UX 11i

 
SOLVED
Go to solution
Rob Molnar
New Member

va_arg() alignment error on HP-UX 11i

I get the following warning when compiling

va_list arglist;
int status

va_start (arglist, f_ptr);
status = va_arg(arglist, int);

in 64-bit mode on 11i:

LP64 migration: Casting from loose to strict alignment: Resulting pointer may be misaligned.

The problem being I can't see why!

This does compile cleanly for char arguments, so it looks like va_arg is mistaking arglist as being single or word byte aligned, but I'm sure all is correctly setup for 8 byte (natural) alignment.

Can anyone shed any light on this? - I've seen a similar question from about a year ago on this forum, but the ansewer just explained the theory, which I'm pretty clear on.
The puzzling thing is that he error seems to be ocurring in the parameter interpretation within va_arg itself?...

Thanks in advance
Rob
2 REPLIES 2
Mike Stroyan
Honored Contributor
Solution

Re: va_arg() alignment error on HP-UX 11i

The va_arg definition is a big macro-
================================================================================
# define va_arg(__list,__mode) \
(sizeof(__mode) > 8l ? \
(( __list = (__va__list)(void*) ((char *)__list + ((long)__list&(0x8l)) + \
(_ROUNDUP_NEXT_DWORD(sizeof(__mode))))), \
(*((__mode *) ((char *)__list - \
(_ROUNDUP_NEXT_DWORD(sizeof(__mode))))))) : \
((__list = (__va__list)(void*) ((char *)__list + sizeof(char *))), \
__is_aggregate(__mode) ? \
(*((__mode *) ((char *)__list - sizeof(char *)))): \
(*((__mode *) ((char *)__list - sizeof(__mode)))) ))

Part of that macro is a cast from char * to __mode *. When you use a __mode of int, the compiler complains about a cast from the less strictly aligned char * to the more strictly aligned int *. It is really alright because the macro code is explicitly computing a correctly aligned pointer. The compiler just can't work that out.
Rob Molnar
New Member

Re: va_arg() alignment error on HP-UX 11i

Thanks Mike, that clears this up nicely.

regards

Rob