Exchange variables between files in C
I have two files:
hudwidgets.c
#include "osd.h"
#include "osdadd.h"
#include <stdio.h>
struct TextSize tsize;
char buff[50];
void hud_draw_lin_compass(int cx, int cy, int tick_maj, int tick_min, int range, int heading)
{
.. important code that uses buff ..
}
hud.c
#include "hudwidgets.h"
#include "hud.h"
#include "osd.h"
#include "osdadd.h"
.. some code ..
void hud_rc_plane_single_frame()
{
fill_mem(0x0000);
if((frame / 50) % 2 == 0)
{
get_next_warning(buff);
}
.. some more code ..
}
The problem is that when I try to compile this, the compiler complains about no buff, but when I try to define it, the linker complains about two variables buff. Catch 22. For this, I ask two questions:
How to fix it;
if you can use the same variable, saving memory, because you need to allocate only one variable (work with a microcontroller with a limited amount of memory.)