help with c code again

OP #1173343
Rate this post
useful
not useful
Hi all.
I have trouble to define structure for all source file.
Before Igive question to how define structure to flash but I define
to ram and define structure *.h files.

typedef struct {
    float  Vmax;
    float  Amax;
    float  Step;
    short  Hold_power;hold ax
    short  Move_power;
                short  Hold_les_power;
    short  Move_more_power;
    } SettingsAX ;

then define :  volatile SettingsAx setting_x =
{300,100,96,20,80,20,120};

but I wat see this structure from all source file to acces it.
compiler show me error : multiple definition . How to correct this
mistake???

regards .

PS: I have book C for microkontroler but it's write for IAR compiler and
some example from book can't use (WINARM conmpiler show error).
OP #1173345
Rate this post
useful
not useful
Martin Thomas wrote:
> Get a "general" C-programming book/tutorial (there are several available
> online for free). Read about declartion and defintion of variables and
> the extern keyword.

I use extern keyword but compiler show warning :
axes.c:18: warning: 'Ax_p_x' initialized and declared 'extern'

I declare it on axes.c file, and structure is define on axes.h .
I want access to this structuro from main function.
I define this in axes.c:
extern volatile Ax_parameter Ax_p_x = {0,0,0,0,0,0,0,0,0,0,0,0,0};
In file axes.h define:
typedef struct {
    DWORD Vactual;
    DWORD Vbefore;
    double Vmax;
          double Vneed;
    double Verror;
    double Acceleration;
    double Sactual;
    double Sstep;
    double Sabsolute;
    double Serror;
    double Time;
    DWORD Timer;
    double Terror;
    } Ax_parameter ;

But if access this structure from main then compiler show error :
cnc1.c:68: error: 'Ax_p_x' undeclared (first use in this function)

using this structure in axes.c file is OK

regards
#1173348
Rate this post
useful
not useful
'extern' means 'this variable is instantiated somewhere else', it is
only used for 'declarations' not 'definitions'.

When you initialise a variable, you can only do that on a 'definition'.
So you had a definition declared extern, which makes no sense. It will
ignore teh extern keyword and instantiate the variable. But if you do
that in a header you end up an instance every time the header is
included and the compiler or linker will complain if you include it more
than once.

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now