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

How does memory get allocated when you declare a structure

How does memory get allocated for the structure on Keil C51 8.x? Is it when I populated the contents of the structure right after declaring the structure does the memory get allocated. I am using a global var. to declare the structure.

Thanks

Sam

Parents
  • Are you talking about the memory layout of the structure or are you talking about placing of structure.

    Declaring variables (be they structures or built-in data types) are no different from any other C/C++ compiler. The handling of global, static and auto variables follows from the requirements of the C standard.

    Declaring a struct just informs about what a struct is - no memory allocated.

    It isn't until you create a variable (whatever data type) that the compiler have to either allocate room on the stack or inform the linker about the symbol name and required amount of memory. How the startup code assigns initialized values to global variables is a completely different matter, and should normally be seen as a "magic" action somehow performed by the startup code.

Reply
  • Are you talking about the memory layout of the structure or are you talking about placing of structure.

    Declaring variables (be they structures or built-in data types) are no different from any other C/C++ compiler. The handling of global, static and auto variables follows from the requirements of the C standard.

    Declaring a struct just informs about what a struct is - no memory allocated.

    It isn't until you create a variable (whatever data type) that the compiler have to either allocate room on the stack or inform the linker about the symbol name and required amount of memory. How the startup code assigns initialized values to global variables is a completely different matter, and should normally be seen as a "magic" action somehow performed by the startup code.

Children
No data