This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ISO C90 checking but ignoring 64-bit printf/scanf warnings

Tom St Denis wrote:
> I don't get the question.  If ISO C90 doesn't mandate support for ll
> what's wrong with the warning?

It clutters compiler output. When compiling I just want to see the
warnings that are interesting, the -pedantic check shows a lot of stupid
mistakes that I make, thus having it enabled is a bonus.

> More so, why are you hell-bent on conforming to C90 then requesting that
> it ignore standards violations?

Because it does more than just checking for the few C90 issues. See the
man page part about '-pedantic' for more info. It is actually not a real
ISO C check, but it does help you find a lot of stupid bugs, and like
most people I am stupid and thus don't mind the computer helping me
resolve those things :)

> Anyways, on a 64-bit platform %ld/%lu should print a 64-bit value since
> for most of these "long" is a native register size.

"Most" is the keyword, not all platforms and compilers (xlc anyone? ;)
do what gcc does and I do like to be able to compile my code on as many
platforms and with as many compilers as possible. You would be surprised
how many silly bugs already appear by just trying to compile your code
on another platform/compiler combo. I try to use this to the full
extent. Thus being able to ignore this minor warning would be very
useful, I know what the warning is for and that it is harmless. Visual
Studio compiler for instance allows you to ignore the warnings based on
their #number they have, that would already be very useful in solving my
little issue. I am more than happy to produce a patch if this feature is
not in gcc yet of course, but first I ask around ;)

Also I use uint64_t and where not needed uint{8|16|32}_t based on need.
"%lu" then doesn't work correctly when moving back again to a 32bit
platform where you want to print a 64-bit integer, as there a %lu is
only 32bits while the variable is 64bits.

That is why I already have:

#ifdef _64BIT
#define FMT_64                  "lu"
#define FMT_64X                 "lx"
#define FMT_64S                 "ld"
#define FMT_TIME                "lu"
#define FMT_64                  "llu"
#define FMT_64X                 "llx"
#define FMT_64S                 "lld"
#define FMT_TIME                "u"

and use something like: printf("%" FMT_64 "u", a); when printing stuff
but %llu is not a ISO C90 thing and thus it warns on those platforms.
On 64bit platforms I am fine with the lu of course and for some odd
reason the compiler then correctly prints 32bit fields without issues.

I could have totally misunderstood that concept though ;)


Attachment: signature.asc
Description: OpenPGP digital signature

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]