This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Memory allaocation for variables in EMBEDDED C

Queries regading C coding for EMBEDDED systems.

If we define Variable of type "int constant i=10,

In Which segment it will be stored??( Code/data/stack )

Similarly for any variable declared as "static".

How it will be decided??

Could you please help me in knowing where the different types of variables in C language?

Parents
  • I'm reasonably sure the 'as-if' rule has been in the C Standard since its first edition (ANSI C89). Without it, optimization would never have been possible. That a const object whose address is never taken doesn't have to have memory allocated is a direct consequence of 'as-if' --- without taking the address, the program can never find out if the const has an address, so the compiler gets to choose whether to give it one or not.

    The difference about 'const' between C++ and C is elsewhere. C++ consts can serve as compile-time constants, just like literals or enum members. C consts are just immutable, but they can't be used to, e.g., dimension an array or bitfield.

Reply
  • I'm reasonably sure the 'as-if' rule has been in the C Standard since its first edition (ANSI C89). Without it, optimization would never have been possible. That a const object whose address is never taken doesn't have to have memory allocated is a direct consequence of 'as-if' --- without taking the address, the program can never find out if the const has an address, so the compiler gets to choose whether to give it one or not.

    The difference about 'const' between C++ and C is elsewhere. C++ consts can serve as compile-time constants, just like literals or enum members. C consts are just immutable, but they can't be used to, e.g., dimension an array or bitfield.

Children
No data