This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[RFA/RFC] Warnings in elf.c (mips-irix)
- From: Joel Brobecker <brobecker at adacore dot com>
- To: binutils at sources dot redhat dot com
- Date: Mon, 28 Mar 2005 20:31:56 -0800
- Subject: [RFA/RFC] Warnings in elf.c (mips-irix)
Hello,
here is another location where a couple of warnings might I think
be pretty easy to fix. Depends on how we want to fix this.
Here is the problem, as reported by GCC (I used a 3.4-based GCC compiler):
gcc -DHAVE_CONFIG_H -I. -I.././bfd -I. -D_GNU_SOURCE -DIRIX_CORE -I. -I.././bfd -I.././bfd/../include -I.././bfd/../intl -I../intl -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror -g -c elf.c -o elf.o
elf.c: In function `elfcore_grok_nto_status':
elf.c:7338: warning: int format, long int arg (arg 3)
elf.c: In function `elfcore_grok_nto_regs':
elf.c:7368: warning: int format, pid_t arg (arg 4)
Here is the actual code that we have at the moment:
sprintf (buf, "%s/%d", base, tid);
And tid is defined as a pid_t.
I looked at the headers, and found that this type is defined in
sys/types.h, which GCC has "diverted" (looking for the right term
for that: has it's own copy in its lib/.../include dir). Here is
the definition:
#if (_MIPS_SZLONG == 32)
[...]
typedef long pid_t; /* proc & grp IDs */
#endif
The irony is that long and int, for n32, are of identical sizes.
But the compiler complains anyway.
The way I fixed it to allow me to continue what I was working on
was to simply add a cast:
sprintf (buf, "%s/%d", base, (int) tid);
This works for mips-irix, since the N64 definition of ptid_t is:
typedef __int32_t pid_t; /* proc & grp IDs */
And this doesn't make things any worse, I guess, since we were
trying to print an int (%d) anway. However, I was wondering if
a safer approach might not be to replace "%d" by "%ld" and then
cast tid to long.
Or maybe something else more elaborated involving autoconf, for
instance?
I think that upcasting to long is the most cost-effective approach.
Opinions?
Thanks,
--
Joel