Operating System - HP-UX
1752711 Members
5592 Online
108789 Solutions
New Discussion юеВ

C Compile Warning on HP-UX 11.31 64-bit Itanium system

 
SOLVED
Go to solution
Curtis Deese
Frequent Advisor

C Compile Warning on HP-UX 11.31 64-bit Itanium system

I am getting the warning below when I try to compile a C program on an HP-UX 11.31 64-bit Itanium system. Why am I getting this warning and how do I resolve the problem?

Thanks

cc -Ae -DHPUX -DORAIA64 -DHPUX_IA64 +DD64 -DSS_64B -I /u01/app/oracle/p
roduct/11.2.0/db_1/precomp/public /u01/app/oracle/product/11.2.0/db_1/rdbms/lib
/u01/app/oracle/product/11.2.0/db_1/precomp/public/ -c DRMSSLogging.c
"DRMSSLogging.c", line 335: warning #2181-D: argument is incompatible with corre
sponding format string conversion
sprintf(SecsStr, "%d", tp.tv_usec);
3 REPLIES 3
Don Morris_1
Honored Contributor
Solution

Re: C Compile Warning on HP-UX 11.31 64-bit Itanium system

Because tv_usec is defined as a long, if I'm reading /usr/include/sys/_timeval.h correctly. (It is a long if _INCLUDE_XOPEN_SOURCE_PRE_500 is defined, and a suseconds_t otherwise... which is just a typedef'd long anyway).

So when you compile 64-bit and use %d you're trying to print a long as an int and the compiler is properly warning you that this isn't compatible. Rather, this should be:
sprintf(SecsStr, "%ld", tp.tv_usec);
Dennis Handly
Acclaimed Contributor

Re: C Compile Warning on HP-UX 11.31 64-bit Itanium system

The aCC6 compiler does format cracking and makes sure your format matches your data types.
It checks sizes and types and whether a format is missing or extra.
Curtis Deese
Frequent Advisor

Re: C Compile Warning on HP-UX 11.31 64-bit Itanium system

Thank you for the responses.

Changing from:

sprintf(SecsStr, "%d", tp.tv_usec);

To

sprintf(SecsStr, "%ld", tp.tv_usec);

resolved the warning.

Curtis