<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Classic/Legacy CodeWarriorのトピックRe: Array structur and extern declaration</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Array-structur-and-extern-declaration/m-p/161286#M2716</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is the typedef of the&amp;nbsp;in the header file with the external declaration?&lt;/P&gt;&lt;P&gt;Also using&amp;nbsp;SENSORS_DATA_STRUCT as struct tag (struct&amp;nbsp;SENSORS_DATA_STRUCT) requires the struct to be defined with the same tag. E.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;typedef struct &lt;FONT color="#0000FF"&gt;SENSORS_DATA_STRUCT&lt;/FONT&gt;&amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8t&amp;nbsp;&amp;nbsp; battery;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8t&amp;nbsp;&amp;nbsp; sensor_connect;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s16t&amp;nbsp; temperature;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u16t&amp;nbsp; humidity;&lt;BR /&gt;} SENSORS_DATA_STRUCT; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;basically in C tag names are in their own namespaces, the code snippet was using the&amp;nbsp;SENSORS_DATA_STRUCT identifier as tag, but did not the identifier as tag too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To avoid&amp;nbsp;duplication&amp;nbsp;you can also just use the tag only, then there is no need for a typedef.&lt;/P&gt;&lt;P&gt;The type definition then looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;struct&amp;nbsp;&lt;FONT color="#0000FF"&gt;SENSORS_DATA_STRUCT&lt;/FONT&gt;&amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8t&amp;nbsp;&amp;nbsp; battery;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8t&amp;nbsp;&amp;nbsp; sensor_connect;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s16t&amp;nbsp; temperature;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u16t&amp;nbsp; humidity;&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tags can also be declared only as "struct&amp;nbsp;SENSORS_DATA_STRUCT;" but you will need the type definition to actually define or access the array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just using the typedef name is also possible as long as you do not need any forward declaration or any recursive references, that only works with tags.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this does not help in your case, please provide the full setup (compilable code) and the exact error message you get from the compiler.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: Note that C++ has different rules in respect to tag names, in C++ tag identifiers get introduced in the enclosing namespace.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 07 Nov 2010 02:03:38 GMT</pubDate>
    <dc:creator>CompilerGuru</dc:creator>
    <dc:date>2010-11-07T02:03:38Z</dc:date>
    <item>
      <title>Array structur and extern declaration</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Array-structur-and-extern-declaration/m-p/161285#M2715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have problem with extern declarition array off structure. I use S08JM.&lt;/P&gt;&lt;P&gt;In main.c I have declaration:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;typedef struct {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8t&amp;nbsp;&amp;nbsp; battery;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8t&amp;nbsp;&amp;nbsp; sensor_connect;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s16t&amp;nbsp; temperature;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u16t&amp;nbsp; humidity;&lt;BR /&gt;} SENSORS_DATA_STRUCT; &amp;nbsp;&lt;BR /&gt;SENSORS_DATA_STRUCT&amp;nbsp;&amp;nbsp;&amp;nbsp; Sensors_data[10];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in second file.c I want to use extern declaration:&lt;/P&gt;&lt;P&gt;extern struct SENSORS_DATA_STRUCT Sensors_data[10];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but I can´t compile, extern declaration structure works, but array structure doesn´t work,&lt;/P&gt;&lt;P&gt;Do you know where is problen? thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Nov 2010 22:09:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Array-structur-and-extern-declaration/m-p/161285#M2715</guid>
      <dc:creator>kurna</dc:creator>
      <dc:date>2010-11-06T22:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Array structur and extern declaration</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Array-structur-and-extern-declaration/m-p/161286#M2716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is the typedef of the&amp;nbsp;in the header file with the external declaration?&lt;/P&gt;&lt;P&gt;Also using&amp;nbsp;SENSORS_DATA_STRUCT as struct tag (struct&amp;nbsp;SENSORS_DATA_STRUCT) requires the struct to be defined with the same tag. E.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;typedef struct &lt;FONT color="#0000FF"&gt;SENSORS_DATA_STRUCT&lt;/FONT&gt;&amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8t&amp;nbsp;&amp;nbsp; battery;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8t&amp;nbsp;&amp;nbsp; sensor_connect;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s16t&amp;nbsp; temperature;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u16t&amp;nbsp; humidity;&lt;BR /&gt;} SENSORS_DATA_STRUCT; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;basically in C tag names are in their own namespaces, the code snippet was using the&amp;nbsp;SENSORS_DATA_STRUCT identifier as tag, but did not the identifier as tag too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To avoid&amp;nbsp;duplication&amp;nbsp;you can also just use the tag only, then there is no need for a typedef.&lt;/P&gt;&lt;P&gt;The type definition then looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;struct&amp;nbsp;&lt;FONT color="#0000FF"&gt;SENSORS_DATA_STRUCT&lt;/FONT&gt;&amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8t&amp;nbsp;&amp;nbsp; battery;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8t&amp;nbsp;&amp;nbsp; sensor_connect;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s16t&amp;nbsp; temperature;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; u16t&amp;nbsp; humidity;&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tags can also be declared only as "struct&amp;nbsp;SENSORS_DATA_STRUCT;" but you will need the type definition to actually define or access the array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just using the typedef name is also possible as long as you do not need any forward declaration or any recursive references, that only works with tags.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this does not help in your case, please provide the full setup (compilable code) and the exact error message you get from the compiler.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: Note that C++ has different rules in respect to tag names, in C++ tag identifiers get introduced in the enclosing namespace.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Nov 2010 02:03:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Array-structur-and-extern-declaration/m-p/161286#M2716</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-11-07T02:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Array structur and extern declaration</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Array-structur-and-extern-declaration/m-p/161287#M2717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem is that any declaration in main.c &amp;nbsp;isn't visible to xxx.c. Simply put the original typedef struct into a h-file, problem solved. Though the array declaration should of course still be in a c-file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Nov 2010 17:08:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Array-structur-and-extern-declaration/m-p/161287#M2717</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2010-11-08T17:08:46Z</dc:date>
    </item>
  </channel>
</rss>

