<?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>static inside struct</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/20247/static-inside-struct</link><description> 
Hi, 

 
I have problem with struct. Here is my code, please correct
me. 

 
 struct main_func
 {
 static int kval;
 int temp3;
 char buf[8];
 }main_f;
 

 
If I do not put &amp;quot;static&amp;quot; to &amp;quot;int kval&amp;quot;, everything OK, Anyone has
idea? 

 
Thanks, 
pak 
 </description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: static inside struct</title><link>https://community.arm.com/thread/112688?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2007 11:00:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7aaec599-8be5-4229-9dc8-162e4f54df64</guid><dc:creator>Per Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;Surely, structures are supposed to be contiguous? SO how could
they share just one element?&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
A struct or class must be continuous, but having a declaration
(Assuming C++) like:&lt;/p&gt;

&lt;pre&gt;
struct/class X {
    static int a;
    int b;
    int c;
};
int X::a;
&lt;/pre&gt;

&lt;p&gt;
just means that the variable a is within the X namespace.&lt;/p&gt;

&lt;p&gt;
The actual struct/class will only contain the member variables b
and c, and they will of course represent a continuous memory
area.&lt;/p&gt;

&lt;p&gt;
Since int X::a is a global variable in the X namespace, it must
exist, even of no variables/objects of type X exists in the
application.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: static inside struct</title><link>https://community.arm.com/thread/98959?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2007 10:54:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:40e365bb-947c-4354-a117-f84f09a0912f</guid><dc:creator>Per Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;The concept isn&amp;#39;t really all that bewildering (think static
member variable of a class), it&amp;#39;s just that C/C++ doesn&amp;#39;t allow it
for structures.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;b&gt;C doesn&amp;#39;t supports it at all&lt;/b&gt;, since it is specifically a
C++ extension.&lt;/p&gt;

&lt;p&gt;
&lt;b&gt;C++ allows it for structures too.&lt;/b&gt; In C++, a struct and a
class is basically the same thing in C++. The class defaults to
protecting it&amp;#39;s members, while a struct defaults to having evrything
public.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: static inside struct</title><link>https://community.arm.com/thread/123685?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2007 10:37:45 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:41c586b1-85a1-4282-9c8f-60916985361e</guid><dc:creator>pak p</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi friends,&lt;/p&gt;

&lt;p&gt;
Thank for suggestion, Actually, I am new to C and beginner of
mcs-51 as well.&lt;/p&gt;

&lt;p&gt;
Thanks,&lt;br /&gt;
pak&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: static inside struct</title><link>https://community.arm.com/thread/112680?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2007 08:25:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4df33c81-3048-4d71-8105-f3858452a860</guid><dc:creator>Christoph Franck</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;How could that be?&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
That wasn&amp;#39;t the question. The question was &amp;quot;What sense would it
make?&amp;quot;.&lt;/p&gt;

&lt;p&gt;
And as I said, it would make sense in certain contexts, and C++
allows this functionality in classes, but it is not allowed in a
structure.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: static inside struct</title><link>https://community.arm.com/thread/98968?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2007 08:09:44 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f6f43a0d-fa5b-487b-b502-9a7c7b5197b0</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;All instances of the structure would share one copy of the
variable ?&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
How could that be?&lt;/p&gt;

&lt;p&gt;
Surely, structures are supposed to be contiguous? SO how could
they share just one element?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: static inside struct</title><link>https://community.arm.com/thread/88199?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2007 07:05:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:044778cf-909d-48d5-841e-54b36a5e8f1d</guid><dc:creator>Christoph Franck</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;Think about it: what sense does it make to have just one member
of a structure as &amp;#39;static&amp;#39;?!&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
All instances of the structure would share one copy of the
variable ?&lt;/p&gt;

&lt;p&gt;
The concept isn&amp;#39;t really all that bewildering (think static member
variable of a class), it&amp;#39;s just that C/C++ doesn&amp;#39;t allow it for
structures.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: static inside struct</title><link>https://community.arm.com/thread/47862?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2007 07:01:03 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3879efe2-8fb0-4f16-816b-fc5aced6ab26</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;I have problem with struct.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Your problem seems to be in understanding how structures and the
&amp;#39;static&amp;#39; keyword work in &amp;#39;C&amp;#39;!&lt;/p&gt;

&lt;p&gt;
Think about it: what sense does it make to have just one member of
a structure as &amp;#39;static&amp;#39;?!&lt;/p&gt;

&lt;p&gt;
What are you actually trying to achieve?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: static inside struct</title><link>https://community.arm.com/thread/47861?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2007 06:23:56 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:507e7e6e-abb8-490a-802d-da3ccb461183</guid><dc:creator>Christoph Franck</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;If I do not put &amp;quot;static&amp;quot; to &amp;quot;int kval&amp;quot;, everything OK, Anyone
has idea?&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
As far as I know, a construction like this is not allowed in C.
Structures cannot have static members (you&amp;#39;re probably thinking in
C++, where classes can have static members).&lt;/p&gt;

&lt;p&gt;
You will need to define the static variable outside your
structure.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>