I've read from a C book that the static and extern storage class variables are allocated memory from heap. Is it true?
I've read from a C book that the static and extern storage class variables are allocated memory from heap. Is it true?
So you're willing to take the word of random people on the internet, over your published authors? Now, sure, if say your author is Schildt, but really?
Quzah.
Hope is the first step on the road to disappointment.
Those random people might be good authors as well that we might don't know... my point is not to argue about the author...
My point is, if you won't believe published authors, why should I think you're going to belive me if I take the time to answer? They took the time to write a book, not just a 15 second post on the internet.
Quzah.
Hope is the first step on the road to disappointment.
Authors are also humans... They may make mistakes in their writings sometimes... Till now I didn't hear such kind of statement regarding variables anywhere....
And I think i can post any doubt regarding C here... Anyone knows the answer can reply...
The language standard does not specify where any of the storage classes are located or what types of mechanisms are used for their storage. For example, it is possible to create a C implementation that is compliant with the standard on hardware that does not provide convenient instructions for implementing a stack. However, since that is the easiest way to implement automatic variables (function scope and lifetime variables) in the many programming languages, most modern hardware provides instruction memory addressing modes that allow easy implementation of a stack.
I work mostly with "free standing" implementations where the code and constants are stored in Flash or equivalent memory. For those that I have been exposed to, the file global and static function variables are allocated to fixed locations in memory. For those that are initialized, the initializers are stored in Flash or equivalent memory and the the variable is stored in RAM.
Most of my projects have chosen not to use allocated (malloc, calloc, or realloc) memory. If they did, they would be managing an area of the same microcontroller RAM.
So in one sense, if the file global and static function variables are allocated in the RAM, then that memory would not be available for use by the heap or the stack. But in another sense, the memory was not allocated from the "heap" but just from RAM.
In a "hosted" environment with virtual memory, the file global and static function variables may be allocated by the operating system using the same underlying mechanism that the allocated memory uses. But it does not have to.
My overall opinion is that I disagree with the author's given your characterization of their opinion. But I would want to see what they specifically wrote before saying they were wrong. As I have indicated above, the answer is not a simple answer.