EmbDev.net

Forum: ARM programming with GCC/GNU tools help with c code again


Author: Sevc Dominik (sevc)
Posted on:

Rate this post
0 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).

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
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.

Author: Sevc Dominik (sevc)
Posted on:

Rate this post
0 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

Author: Sevc Dominik (sevc)
Posted on:

Rate this post
0 useful
not useful
If define onnly easy variable like int or char :
extern volatile char c;

then can use on all source file but with structure it donn't work.

Author: Sevc Dominik (sevc)
Posted on:

Rate this post
0 useful
not useful
Now it work.
In header file I define
extern volatile Ax_parameter Ax_p_x;
In source file I define
volatile Ax_parameter Ax_p_x = {0,0,0,0,0,0,0,0,0,0,0,0,0};

and work all.

thx all.

regards

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 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

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.