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

global variables not initializing to declared values

Maybe I have some setting wrong in my project. At the beginning of my main source file, I include a header that declares several variables as externs. Then I declare and initialize them after the #include.

Main Source:

#include <header.h>
...
const char DEVICE_NAME[] = "ELC";
const char VERSION_NUMBER[] = "F1.0M1.0";
const char CONTROL_PANEL = 1;
...
void main(void)
{
    ...
}

Header (header.h):

#ifndef _HEADER_H
#define _HEADER_H
...
extern char DEVICE_NAME[],VERSION_NUMBER[],CONTROL_PANEL;
...
#endif

The variables are then used in implementation code in another file. This other file and the header are common to several projects that I'm working. (I have restructured my projects per our last discussion.)

The problem that I'm experiencing is that all of the data is initialized to 0 at the beginning of main() rather than the specified values. I don't have any of the .A51 initialization files in my project, so what could be causing this?

Thanks.

Parents
  • You might be better off not explicitly initializing that buffer at all. An initialization to an explict {0} serves no particular purpose anyway --- the result is the same as if you hadn't initialized it all, since the implicit default initialization to all-zeroes would have done the same job, and without wasting several kilobytes of zero bytes in the code image.

Reply
  • You might be better off not explicitly initializing that buffer at all. An initialization to an explict {0} serves no particular purpose anyway --- the result is the same as if you hadn't initialized it all, since the implicit default initialization to all-zeroes would have done the same job, and without wasting several kilobytes of zero bytes in the code image.

Children