<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Declaring structure as extern</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/14365/declaring-structure-as-extern</link><description> I am using a structure named my_struct which is to be declared as extern. 
 
struct my_struct{ 
int a; 
int b; 
}; 
 
struct my_struct first; 
struct my_struct second; 
 
How do I declare the structure in the main file and use the structures first and</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Declaring structure as extern</title><link>https://community.arm.com/thread/37625?ContentTypeID=1</link><pubDate>Mon, 25 Jun 2001 13:08:57 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:55012c92-88c5-4811-9e08-dad255d68e62</guid><dc:creator>Andrew Neil</dc:creator><description>&lt;p&gt;Don&amp;#39;t forget those &amp;amp;ltpre&amp;amp;gt and &amp;amp;lt/pre&amp;amp;gt tags!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;all&lt;/b&gt; your files need to be able to &amp;quot;see&amp;quot; the structure type definition;&lt;br /&gt;
only &lt;b&gt;one&lt;/b&gt; file must actually define the variables (as it is the definition which allocates storage):&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
//&lt;b&gt;main.h&lt;/b&gt;
// Define the structure so that all files can &amp;quot;see&amp;quot; it
struct my_struct
{
   int a;
   int b;
};

// Declare the externs
extern struct my_struct first;
extern struct my_struct second;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;//&lt;b&gt;main.c&lt;/b&gt;
// The header is needed for the struct definition;
// It doesn&amp;#39;t hurt to include the externs,
// and ensures that declarations &amp;amp; definitions match!
#include main.h

// Define the structures - this allocates storage
struct my_struct first;
struct my_struct second;
&lt;i&gt;etc&lt;/i&gt;&lt;/pre&gt;
&lt;pre&gt;
//&lt;b&gt;other.c&lt;/b&gt;
// Include struct definition &amp;amp; extern declarations
#include main.h

&lt;i&gt;etc&lt;/i&gt;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>