Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Per Westermark
05/16/12 03:48
Read: 522 times

#187378 - Tried any good C book lately?
Responding to: ???'s previous message
Note that terminology and a number of answers depends on the specific compiler.

So the way to answer the questions is to read the C standard (or at least a good C book) and to read the manual for the compiler.

Constants are often stored in the text segment, which is normally flash (or write-protected when program is run in RAM in modern PC-class processor). Being constant, they are read-only and don't need to be in memory with R/W access. Having an embedded processor copy the value from the flash (code space) into RAM is obviously a waste of resources, as long as the processor have reasonable instructions for reading data from the code memory.

Data contains global variables (and file-local static variables) that have been given an explicit initial value.
Data also contains static variables declared inside functions, since static, when used with a variable declaration inside a function, means that it's a "global" variable but without being available in the global name space.

BSS contains global variables that haven't been given an explicit initial value. So they get zero-initialized.

Stack isn't just local variables - it's also (normally) for return addresses from function calls. The exception is for processors that have a special return stack in hardware.

What do you think happens during runtime? Haven't your teacher given you some good references to read?
Any C programming book would tell you which variables have explict initial values, which are zero-initialized and which aren't initialized at all.

The compiler manual will tell you where #include looks for files. It is depending on compiler where it will look. But the teacher probably expects you to give two answers here. The C programming books will tell you why.

#define - doesn't store anything anywhere. The C programming books will tell you what #define does.

List of 21 messages in thread
Memory Organization      Yagnesh Mehta      05/16/12 02:39      
   Tried any good C book lately?      Per Westermark      05/16/12 03:48      
      I am using Dennis Ritchie_ANCI C      Yagnesh Mehta      05/16/12 12:25      
         Variables don't move just because you assign to them      Per Westermark      05/18/12 02:33      
            can we start from ZERO........      Yagnesh Mehta      05/18/12 04:27      
               Have you read my original post?      Per Westermark      05/18/12 06:58      
               mixing stuff      Erik Malund      05/18/12 07:13      
                  where it will be for MCU?      Yagnesh Mehta      05/18/12 12:02      
                     is there any book for this fundamental things?      Andy Neil      05/18/12 14:59      
                        and ....      Erik Malund      05/18/12 16:33      
                     In this a general or Specific Question      Neil Kurzman      05/18/12 17:10      
                        its General Que ????      Yagnesh Mehta      05/18/12 23:50      
                           Separate "the C view of program" from "microcontroller view"        Per Westermark      05/19/12 01:48      
                           NO!      Erik Malund      05/19/12 15:53      
                              why not??      Yagnesh Mehta      05/20/12 21:56      
                                 No - generic isn't meaningful      Per Westermark      05/21/12 01:49      
                                 Interview questions can be asked out of limited knowledge      Kalpak Dabir      05/21/12 05:48      
                                    Seldom "one" answer other than to trivial questions      Per Westermark      05/21/12 06:41      
   In Addition      Michael Karas      05/16/12 10:24      
      Embedded?      Per Westermark      05/16/12 10:42      
   sometimes, usually      Erik Malund      05/16/12 13:17      

Back to Subject List