Operating System - HP-UX
1832305 Members
2351 Online
110041 Solutions
New Discussion

C - Compilation Warning..

 
william_39
Occasional Advisor

C - Compilation Warning..

Dear all,
while porting 32 bit proC code on 64 bit HP machine it gives following warnings.

--------------
cc: "cach.c", line 2803: warning 530: LP64 migration: Casting from loose to strict alignment: Resulting pointer may be misaligned.

-------------------

is this major warning ?? will it affect in runtime ?
is there in way to remove this warnings ..?

Thanks in advance,

William
4 REPLIES 4
Deepak Extross
Honored Contributor

Re: C - Compilation Warning..

Can you post line 2803 of cach.c here?
william_39
Occasional Advisor

Re: C - Compilation Warning..

Dear Deepak,
its
----------
city_null_def_ptr=(def *)city_null_def_ptr->next;

------------

thanks for ur response.
william
Deepak Extross
Honored Contributor

Re: C - Compilation Warning..

<< city_null_def_ptr=(def *)city_null_def_ptr->next; >>

This typecasts (city_null_def_ptr->next) to (def *)
Can you check the datatype of city_null_def_ptr->next? Investigate if it would be possible to change this to (def *) in the structure itself.
Rich Homa
New Member

Re: C - Compilation Warning..

Dear william,

We're doing a migration from 10.2 to 11.0 and are encountering the same message (among others) in our compilations. To supplement what Messrs. Basoi and Extross have already said:

There's a file called /opt/ansic/lib/nls/msg/C/cc.msgs that has supposedly has all the error or warning messages the cc compiler can generate. The one you're getting has the following comments:

----------------------------------------------
Warning 530
===========

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

Your program casts a pointer variable whose type is of looser alignment to a
pointer to a type of stricter alignment. The size of the type of the object of
looser alignment is smaller than the size of the type of stricter alignment.
For example,

char * cp1, *cp2;
double * dp;
cp1 = (char *)dp; /* strict to loose
conversion is OK */
dp = (double *)cp2; /* loose to strict conversion;
might cause alignment
problems. */

Using this construct is prone to run-time problems (such as "Bus error")
because of the alignment of the pointer's type not matching the alignment of
the pointer's value. Such conversions should not be used.

ANSI 3.3.4
----------------------------------------------

There is also documentation of some (but not all) of these messages, in addition to some from the C++ compiler, available online at http://docs.hp.com/hpux/onlinedocs/dev/C/B3901BA/errors.html#CWMSGS. And you can look up the ANSI reference, with the rationale behind it, at http://www.lysator.liu.se/c/rat/title.html.

As the comments imply, this warning calls attention to what can theoretically be a serious problem. On the other hand, we got this warning on 10.2 with code that has been running successfully for years. Still, on the assumption that the 64-bit architecture may be fussier than 32-bit on alignment matters, I used the approach Mr. Extross describes to rewrite the code in such a way as to eliminate the messages. If you just want to keep the messages from appearing, you can use Sr. Bassoi's approach or add +W 530 (suppress warning message #530) to your cc flags. (Or if you want the compiler to promote the warning to error level and so terminate the compilation, you can use +We 530).

This may be a lot more information than you wanted, but it may eliminate the need to go to the Forum in order to deal with other messages you might encounter porting your code to the new machines.

Best regards,

Rich