Thread: Storage classes

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    53

    Storage classes

    I've read from a C book that the static and extern storage class variables are allocated memory from heap. Is it true?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    53
    Those random people might be good authors as well that we might don't know... my point is not to argue about the author...

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    53
    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...

  6. #6
    Registered User
    Join Date
    Jun 2010
    Location
    Michigan, USA
    Posts
    143
    Quote Originally Posted by karthik537 View Post
    I've read from a C book that the static and extern storage class variables are allocated memory from heap. Is it true?
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storage classes
    By disruptivetech in forum C Programming
    Replies: 2
    Last Post: 12-02-2005, 09:21 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. need help with storage classes
    By datainjector in forum C Programming
    Replies: 1
    Last Post: 07-03-2002, 04:27 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM