<?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>topic Re: Mix C and assembly in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126669#M365</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, Markie:&lt;BR /&gt;&lt;BR /&gt;Since I don't use CodeWarrior, I can't test this, but it looks like a problem of scope.&lt;BR /&gt;&lt;BR /&gt;In "file1.c", it looks like the variable "i" has file-scope. It does not exist outside of the file "file1.c".&lt;BR /&gt;&lt;BR /&gt;Try declaring it as "global".&lt;P&gt;Message Edited by rocco on &lt;SPAN class="date_text"&gt;2006-08-14&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:32 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Aug 2006 04:31:15 GMT</pubDate>
    <dc:creator>rocco</dc:creator>
    <dc:date>2006-08-15T04:31:15Z</dc:date>
    <item>
      <title>Mix C and assembly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126668#M364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;My problem is how to define a variable that can be use in multi C files and assembly files at a application.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I define a variable in the first C file, for example:&lt;/DIV&gt;&lt;DIV&gt;/* file1.c*/&lt;/DIV&gt;&lt;DIV&gt;int i;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;now I want this variable can be used in another C file and a asm file, for example:&lt;/DIV&gt;&lt;DIV&gt;/* main.c*/&lt;/DIV&gt;&lt;DIV&gt;#include "file1.c"&lt;/DIV&gt;&lt;DIV&gt;main()&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; i=0;&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/*main.asm*/&lt;/DIV&gt;&lt;DIV&gt;XREF i;&lt;/DIV&gt;&lt;DIV&gt;...&lt;/DIV&gt;&lt;DIV&gt;LDD #0&lt;/DIV&gt;&lt;DIV&gt;STD i&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;but it can not be link correctly withing CW for HCS12 v3.1.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Please help me!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Aug 2006 14:24:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126668#M364</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-14T14:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Mix C and assembly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126669#M365</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, Markie:&lt;BR /&gt;&lt;BR /&gt;Since I don't use CodeWarrior, I can't test this, but it looks like a problem of scope.&lt;BR /&gt;&lt;BR /&gt;In "file1.c", it looks like the variable "i" has file-scope. It does not exist outside of the file "file1.c".&lt;BR /&gt;&lt;BR /&gt;Try declaring it as "global".&lt;P&gt;Message Edited by rocco on &lt;SPAN class="date_text"&gt;2006-08-14&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:32 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Aug 2006 04:31:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126669#M365</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-08-15T04:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Mix C and assembly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126670#M366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;What is the message the linker generates?&lt;/P&gt;&lt;P&gt;CrasyCat&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Aug 2006 15:41:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126670#M366</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2006-08-15T15:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Mix C and assembly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126671#M367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The linker error is likely there because you are including a c-file. Never do that, you should only include h-files. This is how it is done properly:&lt;BR /&gt;&lt;BR /&gt;/* file.h */&lt;BR /&gt;extern int i;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* file.c */&lt;BR /&gt;#include "file.h"&lt;BR /&gt;int i;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* main.c */&lt;BR /&gt;#include "file.h"&lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;i=0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* file.asm */&lt;BR /&gt;&lt;BR /&gt;XREF i&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Aug 2006 18:33:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126671#M367</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2006-08-15T18:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Mix C and assembly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126672#M368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Yeah, I placed the variable "i" in the .h file.&lt;/P&gt;&lt;P&gt;First, I do not use "extern", and the linker note "Link Error : L1818: Symbol - i duplicated in file1.c.o and main.c.o".&lt;/P&gt;&lt;P&gt;Then I added "extern", linker show "Link Error: L1822: Symbol i in file ...file.asm.o is undifined".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Aug 2006 09:26:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126672#M368</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-16T09:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Mix C and assembly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126673#M369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;It's seemed that "global" not be supported by CW.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Aug 2006 09:30:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126673#M369</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-16T09:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Mix C and assembly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126674#M370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;You didn't do as shown in my example then. Did you add it to the .c file?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If you declare a variable as&lt;BR /&gt;&lt;BR /&gt;int i;&lt;BR /&gt;&lt;BR /&gt;as shown in my example it -will- be global and every other file in your project can access it. Unless you use the "static" keyword. This is very basic C knowledge.&lt;BR /&gt;&lt;BR /&gt;And XREF works just fine - I'm also using CW3.1 for HCS12.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Aug 2006 13:43:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126674#M370</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2006-08-16T13:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Mix C and assembly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126675#M371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Thanks a lot!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am now declare i in a *.h file:&lt;/DIV&gt;&lt;DIV&gt;/*&amp;nbsp;file.h */&lt;/DIV&gt;&lt;DIV&gt;int i;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;and be&amp;nbsp;included and used in&amp;nbsp;file.c, main.c and file.asm:&lt;/DIV&gt;&lt;DIV&gt;/* file.c */&lt;/DIV&gt;&lt;DIV&gt;#include "file.h"&lt;/DIV&gt;&lt;DIV&gt;void file()&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; i = 0;&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* main.c */&lt;/DIV&gt;&lt;DIV&gt;#include "file.h"&lt;/DIV&gt;&lt;DIV&gt;void main()&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; i = 1;&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* file.asm */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; XREF i&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; LDD #0&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; STD i&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;but if I declare "i" as a global variable in the h file, linker show "i" be duplicated by the two c files;&lt;/DIV&gt;&lt;DIV&gt;if i declare as extern or static, linker show "i" undefined in asm file.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Aug 2006 14:22:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126675#M371</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-16T14:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Mix C and assembly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126676#M372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;I notice the different between your sample and mine:&lt;/P&gt;&lt;P&gt;Declare "i" in the h file as "extern", and be included in the two c file, alse be included in the asm file.&lt;/P&gt;&lt;P&gt;I notice that in the first c file you re-declare the variable "i", then everythink ok!&lt;/P&gt;&lt;P&gt;I just wondered whether the two "i" (file.h and file.c)&amp;nbsp;share the same RAM space?&lt;/P&gt;&lt;P&gt;Could you explare it for me?&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Aug 2006 14:37:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126676#M372</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-16T14:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Mix C and assembly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126677#M373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;When you type extern in front of the variable, you aren't declaring the actual variable. You just tell the compiler that we have a variable called 'i' but it is allocated elsewhere. By doing so, every c-file that includes the h-file gets the info that 'i' exists.&lt;BR /&gt;&lt;BR /&gt;Note however that you should place the "extern" in the same memory segment as the variable:&lt;BR /&gt;&lt;BR /&gt;/* file.h */&lt;BR /&gt;&lt;BR /&gt;#pragma DATA_SEG MY_RAM&lt;BR /&gt;extern int i;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* file.c */&lt;BR /&gt;&lt;BR /&gt;#pragma DATA_SEG MY_RAM&lt;BR /&gt;int i;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Aug 2006 17:25:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126677#M373</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2006-08-16T17:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: Mix C and assembly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126678#M374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;I got it!&lt;/P&gt;&lt;P&gt;Thank you again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Aug 2006 19:12:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Mix-C-and-assembly/m-p/126678#M374</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-16T19:12:40Z</dc:date>
    </item>
  </channel>
</rss>

