Variables stored differently in PC & uC ??

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

Hello all,

this seems an easy question, but not to me.

- Are variables of type (register, const, static, auto, extern, global) stored differently in microcontroller when compared to their storage in PC ?

all i know is
Auto ---> stack
Register --> in main memory CPU
static/ global ---> data segment
extern ---> data segment
const --> (vague) somewhere in ROM
and..
memory allocation (malloc) is done at heap.

but i do not have a clear picture of these things.

Can someone explain this point with reference to PC and atmega controllers for example.

regards
cal.

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

const does not imply ROM, const only implies that code should not try to write to it. Const variables are still stored in the data segment.

In general yes items are stored the same on a uC as they are on a PC, unless you specify otherwise. [ie using the flash or progmem attribute to specify putting something in ROM, the attribute will vary with your compiler as these are non-standard extensions to support the harvard architecture]

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

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

At byte and bit level, there can be differences in storage due to differences in endianness. This might or might not be what the OP is referring to.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

And in struct on PC you can expect some holes between members to align struct members for faster access. This can be changed using pragmas.