sizeof int in AVR

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

just wondering if the int type in GCC/AS6 are all using 16bits size in all the chip?

or could they be different depends on the chip?

Zhuhua Wu - Electronic Engineering Student

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

By definition, an integer in C is at least 16 bits.

For all (x)(mega)(tiny)AVR8s, an int is 16 bit.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks :)

Zhuhua Wu - Electronic Engineering Student

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't rely on knowing the size of int, use

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And on the AVR32 (with the GCC toolchain) an int is 32-bits.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

good to know this

mikech wrote:
And on the AVR32 (with the GCC toolchain) an int is 32-bits.

Zhuhua Wu - Electronic Engineering Student

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Exactly why I wrote AVR8 ;)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note that following a request I have split the discussion about using sizeof() from here to a separate thread:

https://www.avrfreaks.net/index.p...

Moderator

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Don't rely on knowing the size of int, use
That won't help with the promotion rules. Promotion rules are determined by the size of int, no matter if you use a int16_t, for example.

That means: on a 32-bit platform you might get different results than on a 16-bit platform, for example in (a+b)/2 if the sum doues no more fit in a 16-bit value but the result does.

avrfreaks does not support Opera. Profile inactive.