472,344 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,344 software developers and data experts.

Extern union

Hi
I have a header file in which a union is defined .
Expand|Select|Wrap|Line Numbers
  1. union {
  2.  Uint32 uint;
  3.  short channel[2];
  4.  } AIC_data; 
I want to declare it to be extern so as to avoid multiple definitions while the header file is included more than once by the source files in my project which i am doing using Code Composer Studio(which has C,C++ compiler).
When i declare it to be extern the error message showing is "Storage class cannot be specified here".I would like to know the syntax for doing it.
Any help would be appreciated.
prem
May 2 '07 #1
3 12447
Banfa
9,065 Expert Mod 8TB
Probably the best (or easiest) thing would be to split the type definition and the data declaration and definition.

You should declare the type and the data in the header file and then define the data in a c/cpp file.

Expand|Select|Wrap|Line Numbers
  1. // Header
  2. union MyUnion {
  3.  Uint32 uint;
  4.  short channel[2];
  5.  }; 
  6.  
  7. extern union MyUnion AIC_data;
  8.  
  9. // Code file
  10. union MyUnion AIC_data;
  11.  
May 2 '07 #2
JosAH
11,448 Expert 8TB
Hi
I have a header file in which a union is defined .
Expand|Select|Wrap|Line Numbers
  1. union {
  2.  Uint32 uint;
  3.  short channel[2];
  4.  } AIC_data; 
I want to declare it to be extern so as to avoid multiple definitions while the header file is included more than once by the source files in my project which i am doing using Code Composer Studio(which has C,C++ compiler).
When i declare it to be extern the error message showing is "Storage class cannot be specified here".I would like to know the syntax for doing it.
Any help would be appreciated.
prem
I normally use typedefs for readability reasons. This is how I do these things:
1) define the type in a foo.h file and declare a global variable of that type:
Expand|Select|Wrap|Line Numbers
  1. #ifndef _FOO_H_
  2. #define _FOO_H_
  3. typedef union {
  4.  Uint32 uint;
  5.  short channel[2];
  6.  } my_union_t; 
  7. ...
  8. extern my_union_t AIC_data;
  9. #endif
2) then in a foo.c file I define the thing:
Expand|Select|Wrap|Line Numbers
  1. #include "foo.h"
  2. ...
  3. my_union_t AIC_data;
3) and in every other .c file that needs that global union:
Expand|Select|Wrap|Line Numbers
  1. #include "foo.h"
kind regards,

Jos
May 2 '07 #3
Thanks Banfa,
your advice helped me to solve the problem
prem




Probably the best (or easiest) thing would be to split the type definition and the data declaration and definition.

You should declare the type and the data in the header file and then define the data in a c/cpp file.

Expand|Select|Wrap|Line Numbers
  1. // Header
  2. union MyUnion {
  3.  Uint32 uint;
  4.  short channel[2];
  5.  }; 
  6.  
  7. extern union MyUnion AIC_data;
  8.  
  9. // Code file
  10. union MyUnion AIC_data;
  11.  
May 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ik | last post by:
Hello all, Under C++ when 'extern' is used with out the string literal "C" does it act the same as a 'static' ? When is it appropriate using...
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention....
6
by: Neil Zanella | last post by:
Hello, I would like to know what the C standards (and in particular the C99 standard) have to say about union initializers with regards to the...
4
by: dyu9999 | last post by:
Hi, I have a following error and would appreciate any help. ======================================================== * in foo.c I have ...
19
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the...
5
by: siliconwafer | last post by:
Hi all, I wanted to know that is use of extern keyword mandatory in case of global variables and functions used in other source files? i.e...
17
by: Tapeesh | last post by:
I would like to know what is the expected behaviour of C compilers when an extern decleration is intialized. When the following code is compiled...
5
by: Christian Christmann | last post by:
Hi, I've tree questions on the storage class specifier "extern": 1) Code example: int main( void ) { int b = -2; // my line 3 if ( a ) {
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.