This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UNION and STRUCT

I'd like to make a definition of union in one file and call it from others. Union needs to consists structures in it. Is it possible?
Thank you,
Goran

Parents Reply Children
  • If you want to export the global variable as well as just the type, you might want to put the

    extern MyUnion mine;

    in the MyUnion.h header file as well.

    There should be only one actual definition of the variable "mine" in a .c somewhere, but the extern reference can be used by all.

  • "There should be only one actual definition of the variable "mine" in a .c somewhere, but the extern reference can be used by all."
    (my emphasis).

    Note that you can even include the header with the extern reference in the .c source file with the actual definition of the variable; in fact, I recommend that you should do this - this is the only way that you can get the compiler to warn you when your extern reference gets out-of-step with the actual definition of the variable!

    Note that this is all standard 'C' stuff - nothing specifically to do with Keil at all.