Suppose i don't have an os and I write a c and compile a program to run on the computer without os. My program has a line int a = 0; My question is where is the variable a is stored and how does the program determine where to store the variable?
Asked
Active
Viewed 77 times
-1
-
possible duplicate of [Can I execute any c made prog without any os platform?](http://stackoverflow.com/questions/1722687/can-i-execute-any-c-made-prog-without-any-os-platform) – David C. Rankin Apr 01 '15 at 18:12
-
Memory allocation for static and auto variables is a function of the compiler and linker, not the OS. As for where a variable is stored, that depends on how and where it is declared. – John Bode Apr 01 '15 at 18:43
1 Answers
0
It depends on where and how you declared it.
If it's a global variable, or a static variable declared inside a function, the linker decides where to put it (typically in the .data or .bss section, for initialized or uninitialized data, respectively). Your executable loader (or, if you don't have an OS under it, your bootloader) would decide exactly where in RAM it finally goes.
If it's a local variable, the compiler will put it on your call stack or in a register.

Emily
- 543
- 4
- 12