Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ONE global var declaration, but multiple instantiations ? (Read 649 times)
GoofBall
Newbies
*
Offline


Posts: 9
Joined: Jun 22nd, 2018
ONE global var declaration, but multiple instantiations ?
Jan 22nd, 2021 at 10:17pm
Print Post  
I have a.h  and a.cpp,  as well as b.h and b.cpp.  This is in addition to myproject.ino, and all in the same folder.

a.h has global var declaration: static char schedfile[1000]; 

b.cpp has:  #include "a.h"

But upon compilation:  TWO instantiations are shown in the .map file:
.bss._ZL9schedfile
                0x3fff1224      0x3e8 project_main.cpp.o
.bss._ZL9schedfile
                0x3fff160c      0x3e8 schedule_file.cpp.o

I'm baffled.  Anyone have any ideas?
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2145
Joined: Feb 13th, 2019
Re: ONE global var declaration, but multiple instantiations ?
Reply #1 - Jan 23rd, 2021 at 12:40pm
Print Post  
Do you get the same issue compiling in Arduino IDE?

Does the variable need to be marked "extern" so it is the only one referenced by all instances?

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ONE global var declaration, but multiple instantiations ?
Reply #2 - Feb 4th, 2021 at 6:23pm
Print Post  
Also to ensure you use our or an arduino example to create a header file. Those examples add a condition to the top of the header that ensures the header is compiled only once. Without that your report would be normal behavour.
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint