Re: Compiler warning



mattia <gervaz@xxxxxxxxx> writes:

On Thu, 31 Jul 2008 12:26:02 +0000, Chris Torek wrote:

In article <4891adbd$0$41657$4fafbaef@xxxxxxxxxxxxxxxxxxx>, mattia
<gervaz@xxxxxxxxx> wrote:
Hi all, I've got to use this declaration:

unsigned long h = 2166136261;

but the gcc compiler warns me saying "warning: this decimal constant is
unsigned only in ISO C90".

What should I do?

You do not *have* to do anything, but your best bet is to write an
unsigned long constant, so that it is unsigned long in C99 as well:

unsigned long h = 2166136261UL;

The U suffix means "unsigned" and the L suffix means "long", and as with
declarations, the letters can appear in either order, but "UL" is more
conventional than "LU". (Unlike declarations, the letters can also be
either lowercase or uppercase, but lowercase L is too-often mistaken for
the digit 1, so stick with uppercase.)

Ok, thanks, but why the only way to display the number using printf is
printf("%lu\n", h)?

I think you are asking why printf does not also accept %ul for
unsigned long. I think there are really two reasons:

(1) Formats are interpreted at run-time (usually) so it is good make
then as easy to process as possible. Thus restricting the format to

% <things that alter the meaning> <one of i, d, u, f, etc>

makes it easier to process that allowing any ordering.

(2) There would have to be a way to mark the end of a format (making
it more complex) or it would be very hard to use. If %d and %dl are
both valid, how do I print a quantity of litres like 57l?

--
Ben.
.



Relevant Pages

  • Re: Compiler warning
    ... but the gcc compiler warns me saying "warning: this decimal constant is ... letters can also be either lowercase or uppercase, ... L is too-often mistaken for the digit 1, so stick with uppercase.) ...
    (comp.lang.c)
  • Re: Compiler warning
    ... but the gcc compiler warns me saying "warning: this decimal constant is ... declarations, the letters can appear in either order, but "UL" is more ... either lowercase or uppercase, but lowercase L is too-often mistaken for ... the digit 1, so stick with uppercase.) ...
    (comp.lang.c)
  • Re: Why this works?!
    ... Since this only works if SIZE is a decimal constant anyway, ... It is nicer to have the 10 in only one place -- used for the array ... size and the input specification. ...
    (comp.lang.c)
  • Re: Why this works?!
    ... Ben Bacarisse wrote: ... Since this only works if SIZE is a decimal constant anyway, ... I'm out of imagination today...) ...
    (comp.lang.c)