0

Solved.

I was trying to control the value of a variable in IAR Embedded Workbench (working with STM32F303xC microcontroller). I declared the variables in the library.h files as:

extern int my_variable1;
extern float another_variable //... etc

Then in library.c

int my_variable1 = 15;
float another_variable = 328.47;

In main.c

my_variable1 = 38;
another_variable = pow(10,2) + another_variable/8

But in watch, live watch and quick watch it rises the error : (column 1) Unknown or ambiguous symbol.

I wrote several programs with this IDE and the declaration of static variables worked and it allowed me to see the variable's value using the watches. In other programs i declared the variable as

int my_variable1;

In the main file, outside the main function and it worked too.

How can i solve this error?

As far as we go, it seems the the real question is:

There is a way to show in IAR Embedded Workbench the value of variables shared between .c-s?

EagleOne
  • 541
  • 1
  • 10
  • 28
  • What is the scope of declare static var into a header?.. – LPs Feb 23 '16 at 16:06
  • In that way you can read only the .h and recognize all the variables and the function that this header provides. – EagleOne Feb 23 '16 at 16:08
  • There is no reason why you would ever declare variables in header files to begin with. Making a variable "global static" makes even less sense, it is like going to the paint store and asking for "white black" paint. – Lundin Feb 23 '16 at 16:30
  • Moreover in this way you could share only the declarations in .h without sharing the .c files (and the source code) – EagleOne Feb 23 '16 at 16:30
  • global static is a sort of oxymoron – EagleOne Feb 23 '16 at 16:30

2 Answers2

3

The IDE Embedded Workbench, as form of optimization, doesn't allocate the variables that are declared but not used. So those variables cannot be showed in the watches.

EagleOne
  • 541
  • 1
  • 10
  • 28
1

The problem is that you declare the variable static.

This means you will have a discrete copies of those variable for each file that #include the hedaer file.

I guess that static watch work as far as you are breaking execution inside a specific function files. It will show you the local scoped copy of variable.

LPs
  • 16,045
  • 8
  • 30
  • 61
  • How should I declare a variable that has to be used by more than one .c? As extern? (I have an error so, too) – EagleOne Feb 23 '16 at 16:11
  • @EagleOne Surely not static. `int var;` in the `.c` file. `extern int var;` into header file. – LPs Feb 23 '16 at 16:12
  • Question updated using answers from: http://stackoverflow.com/questions/1045501/how-do-i-share-variables-between-different-c-files and http://stackoverflow.com/questions/3010647/shared-global-variables-in-c but still not working – EagleOne Feb 23 '16 at 16:26
  • @EagleOne Are each variable name used as unique in your project? – LPs Feb 23 '16 at 16:29
  • Yes. Declared as extern in lib.h, declared and defined in lib.c and used in some operation in main.c – EagleOne Feb 23 '16 at 16:29
  • @EagleOne What if you break inside a function that use one of those vars? Could you see the value in a standard watch view? – LPs Feb 23 '16 at 16:30
  • No values showed. After compilation, linking and flashing, when i start the program i can only see the error instead of the variable's value – EagleOne Feb 23 '16 at 16:32
  • The workbench gave me this error even trying to declare the variables only in main.c files as usual... – EagleOne Feb 23 '16 at 16:40
  • @EagleOne never happend to me. I worked a lot with that IDe without problem watching vars. – LPs Feb 23 '16 at 16:42
  • Finally got it. I had that problem only for few variables. Those variables were not modified. I think that the workbench, as optimization, doesn't allocate variables not used. Thanks. The problem is solved using the method i wrote above. Good work and have a nice day. – EagleOne Feb 23 '16 at 16:43