Welcome, Guest. Please login or register.

Author Topic: Longs, ints and printf (ansi-C)  (Read 2360 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Longs, ints and printf (ansi-C)
« on: March 14, 2004, 12:57:13 PM »
Quote
a) ints and longs are usually the same these days, aren't they? The ansi-C reference I'm looking at claims ints are 16 bit and longs are 32 bits, but ints are 32 as well these days?

Your reference is sh1te then. There are no strict fixed sizes, but certain rules. For example:
8 bits <= char <= short <= int <= long
16 bits <= short <= int <= long
32 bits <= long

If you must know the limits for specific types on the particular implementation, see .

Quote
b) why won't printf print longs and is there any way around that (besides casting to integer)?

%ld prints long.

Quote
c) Why does an unsigned integer overflow with values such as FFFF FFAA?

It does overflow if you add something to that value so that the result would be > FFFFFFFF.

Quote
d) Working with longs I appear to get no overflows no matter how big a number I use, at least the if(number < 0) is never true for longs. Why is that?

Because you use unsigned long? With unsigned type (number < 0) is never true.