From: Andrew Falanga on
Hi,

I know that %u is for unsigned integers, but, if memory serves me,
that's only for 32 bit integers. What modifier would I use just
before the 'u'? For example, (again if memory serves), to display an
object of type long long, I would use "%ll", correct? So, what's
necessary for an unsigned 64 bit integer?

You know, I don't know if it would make any difference but I'm using a
64 bit compiler. I'm wondering if, in this case, it matters at all.
Since the word size of the compiler is 64 bits, would I simply use %u
and call it good?

Andy
From: Richard Heathfield on
Andrew Falanga said:

> Hi,
>
> I know that %u is for unsigned integers, but, if memory serves me,
> that's only for 32 bit integers.

Not so. It is for unsigned ints.

> What modifier would I use just
> before the 'u'? For example, (again if memory serves), to display an
> object of type long long, I would use "%ll", correct?

Nearly. To display the /value/ of an object of type long long, in a decimal
representation, you would use "%lld".

> So, what's
> necessary for an unsigned 64 bit integer?

It depends on the type. If it's a short int, use "%hu". If it's an int, use
"%u". If it's a long int, use "%lu". And if it's a long long int (always
assuming your platform supports them, of course), use "%llu". C imposes no
upper limit on the width of the basic integral data types. Even char is
allowed to be 64 bits wide - or more!

> You know, I don't know if it would make any difference but I'm using a
> 64 bit compiler.

C is C. It doesn't matter how many bits your compiler has, as long as it
conforms to the language spec.

> I'm wondering if, in this case, it matters at all.
> Since the word size of the compiler is 64 bits, would I simply use %u
> and call it good?

No, your choice should be based on the specific type, not on bit-count.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
From: Andrew Falanga on
On May 27, 9:31 am, Richard Heathfield <r...(a)see.sig.invalid> wrote:
> Andrew Falanga said:
>
> > Hi,
>
> > I know that %u is for unsigned integers, but, if memory serves me,
> > that's only for 32 bit integers.
>
> Not so. It is for unsigned ints.
>
> > What modifier would I use just
> > before the 'u'? For example, (again if memory serves), to display an
> > object of type long long, I would use "%ll", correct?
>
> Nearly. To display the /value/ of an object of type long long, in a decimal
> representation, you would use "%lld".
>
> > So, what's
> > necessary for an unsigned 64 bit integer?
>
> It depends on the type. If it's a short int, use "%hu". If it's an int, use
> "%u". If it's a long int, use "%lu". And if it's a long long int (always
> assuming your platform supports them, of course), use "%llu". C imposes no
> upper limit on the width of the basic integral data types. Even char is
> allowed to be 64 bits wide - or more!
>
> > You know, I don't know if it would make any difference but I'm using a
> > 64 bit compiler.
>
> C is C. It doesn't matter how many bits your compiler has, as long as it
> conforms to the language spec.
>
> > I'm wondering if, in this case, it matters at all.
> > Since the word size of the compiler is 64 bits, would I simply use %u
> > and call it good?
>
> No, your choice should be based on the specific type, not on bit-count.
>
> --
> Richard Heathfield <http://www.cpax.org.uk>
> Email: -http://www. +rjh@
> Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
> "Usenet is a strange place" - dmr 29 July 1999

Thank you. To be honest, it's been a while since I've had to use
format specifiers. Most of the code I've written lately I've been
able to use the C++ I/O objects. Although this is C++, I'm coming
into the project late and don't quite know the full extent of the
environment. I don't know why, but we have to use format specifiers
for output. Thanks again.

Andy
From: Andrew Falanga on
On May 27, 7:58 pm, Barry Schwarz <schwa...(a)dqel.com> wrote:
> On Tue, 27 May 2008 08:45:29 -0700 (PDT), Andrew Falanga
>
>
>
> <af300...(a)gmail.com> wrote:
> >On May 27, 9:31 am, Richard Heathfield <r...(a)see.sig.invalid> wrote:
> >> Andrew Falanga said:
>
> >> > Hi,
>
> >> > I know that %u is for unsigned integers, but, if memory serves me,
> >> > that's only for 32 bit integers.
>
> >> Not so. It is for unsigned ints.
>
> >> > What modifier would I use just
> >> > before the 'u'? For example, (again if memory serves), to display an
> >> > object of type long long, I would use "%ll", correct?
>
> >> Nearly. To display the /value/ of an object of type long long, in a decimal
> >> representation, you would use "%lld".
>
> >> > So, what's
> >> > necessary for an unsigned 64 bit integer?
>
> >> It depends on the type. If it's a short int, use "%hu". If it's an int, use
> >> "%u". If it's a long int, use "%lu". And if it's a long long int (always
> >> assuming your platform supports them, of course), use "%llu". C imposes no
> >> upper limit on the width of the basic integral data types. Even char is
> >> allowed to be 64 bits wide - or more!
>
> >> > You know, I don't know if it would make any difference but I'm using a
> >> > 64 bit compiler.
>
> >> C is C. It doesn't matter how many bits your compiler has, as long as it
> >> conforms to the language spec.
>
> >> > I'm wondering if, in this case, it matters at all.
> >> > Since the word size of the compiler is 64 bits, would I simply use %u
> >> > and call it good?
>
> >> No, your choice should be based on the specific type, not on bit-count.
>
> >> --
> >> Richard Heathfield <http://www.cpax.org.uk>
> >> Email: -http://www. +rjh@
> >> Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
> >> "Usenet is a strange place" - dmr 29 July 1999
>
> >Thank you. To be honest, it's been a while since I've had to use
> >format specifiers. Most of the code I've written lately I've been
> >able to use the C++ I/O objects. Although this is C++, I'm coming
> >into the project late and don't quite know the full extent of the
> >environment. I don't know why, but we have to use format specifiers
> >for output. Thanks again.
>
> I have no idea if C++ adopted the exact width integer types of C99 but
> if your system supports int64_t and uint64_t (the only types
> guaranteed to be exactly 64 bits) then it should support the
> corresponding formats (PRId64 and PRIu64).
>
> Remove del for email

Thanks. I learned something interesting. Using %lu produced nothing
but a '?' in the output as did using %u. The only thing that works is
%ld, but this would be for a signed in, no?

Andy
From: Andrew Falanga on
On May 28, 10:33 am, Keith Thompson <ks...(a)mib.org> wrote:
> Andrew Falanga <af300...(a)gmail.com> writes:
>
> [ questions and answers about printf formats deleted ]
>
> > Thanks. I learned something interesting. Using %lu produced nothing
> > but a '?' in the output as did using %u. The only thing that works is
> > %ld, but this would be for a signed in, no?
>
> "%ld" is for signed long int (also known as signed long, long int, or
> long). "%lu" is for unsigned long int.
>
> If "%ld" works, I'd be very surprised if "%lu" produces just a '?'.
> Can you show us some actual code that exhibits this behavior?
>
> Note: By "actual code" I mean a small, self-contained, compilable
> program that we can try outselves without modification.
> Copy-and-paste your actual code; don't re-type it.
>
> --
> Keith Thompson (The_Other_Keith) ks...(a)mib.org <http://www.ghoti.net/~kst>
> Nokia
> "We must do something. This is something. Therefore, we must do this."
> -- Antony Jay and Jonathan Lynn, "Yes Minister"

I wished I could give you what you're asking for here but in this case
I can't. Besides, I'm so new to the build environment that, to be
honest if I could copy/paste, it wouldn't do much good. Nowhere do I
see people using printf() or other standard calls. It's all things
like:

Print()
UINT64

and so forth. Since both of these, on the surface anyway, go outside
of standard C or C++, it's beyond the scope anyway. I don't even know
what include files are necessary for all this magic to take place.
Basically, this is what I have (that would be compilable but for my
lack of understanding the environment):

// some includes here, don't know what
int main() {
UINT64 bigInt = 3;

Print("bigInt contains %lu\n", bigInt);

return 0;
}

That's what I have, but the output looks like:
bigInt contains ?

The compiler isn't catching that the %ld is for a signed, rather than
unsigned, 64bit int. For this reason, I'm betting that somewhere,
someone's not turning on something like "-Wformat" (that's for GNU
gcc). I dug up that little tid-bit after finding out why I've been
slapped before in the past for using a format specifier that didn't
match the data type.

Shoot, this environment is so unfamiliar to me that I've never seen a
system where you need to define the entry point in a header file, but
you do with this.

Andy