Welcome, Guest. Please login or register.

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

Description:

0 Members and 1 Guest are viewing this topic.

Offline elendilTopic starter

  • Sr. Member
  • ****
  • Join Date: Nov 2002
  • Posts: 324
    • Show all replies
    • http://www.idiot.fnuck.dk
Longs, ints and printf (ansi-C)
« on: March 14, 2004, 12:01:06 PM »
Hi...

I have just finished my little hexadecimal to decimal tool, and again stumbled on the stupid 32 bit barrier of integer values...

A few questions:

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?

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

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

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?

d) Work-arounds? :)

Thanks,

Sincerely,

-Kenneth Straarup.
 

Offline elendilTopic starter

  • Sr. Member
  • ****
  • Join Date: Nov 2002
  • Posts: 324
    • Show all replies
    • http://www.idiot.fnuck.dk
Re: Longs, ints and printf (ansi-C)
« Reply #1 on: March 14, 2004, 02:47:49 PM »
Hi,

I'm using gcc (3.3 for osX, I think).

It seems some of my problems are related to the fact that gcc ignores my pretty 'unsigned' letters in front of the variables. At least I have overflows at less than 32 bits, and I can put negative values into them as well.
Any suggestions?

%ld worked for printing longs, btw, so thanks.

Sincerely,

-Kenneth Straarup.
 

Offline elendilTopic starter

  • Sr. Member
  • ****
  • Join Date: Nov 2002
  • Posts: 324
    • Show all replies
    • http://www.idiot.fnuck.dk
Re: Longs, ints and printf (ansi-C)
« Reply #2 on: March 14, 2004, 08:44:53 PM »
Hi,

Thanks for that clarification. I'll go try that right away...or when I'm allowed to play with the gf's ibook again - my own laptop is at the repair shop atm, sniff sniff :)

Sincerely,

-Kenneth Straarup.