<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.ethernut.de/nutwiki/index.php?action=history&amp;feed=atom&amp;title=Determine_Compiler_Version</id>
		<title>Determine Compiler Version - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.ethernut.de/nutwiki/index.php?action=history&amp;feed=atom&amp;title=Determine_Compiler_Version"/>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Determine_Compiler_Version&amp;action=history"/>
		<updated>2026-05-23T05:35:57Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://www.ethernut.de/nutwiki/index.php?title=Determine_Compiler_Version&amp;diff=56&amp;oldid=prev</id>
		<title>Harald: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Determine_Compiler_Version&amp;diff=56&amp;oldid=prev"/>
				<updated>2016-10-27T16:02:53Z</updated>
		
		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 16:02, 27 October 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;' lang='en'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Harald</name></author>	</entry>

	<entry>
		<id>http://www.ethernut.de/nutwiki/index.php?title=Determine_Compiler_Version&amp;diff=55&amp;oldid=prev</id>
		<title>AdrianPyka: /* Test Environments */</title>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Determine_Compiler_Version&amp;diff=55&amp;oldid=prev"/>
				<updated>2010-08-02T11:54:16Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Test Environments&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Test Environments ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;smalldiv&amp;quot;&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; |&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | Hardware Comments&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.6.3'''&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.6.4'''&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.7.4'''&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.8.0'''&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.8.7'''&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Ethernut 1.3 H&amp;lt;/span&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
| OK&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/determine-compiler-version-enut13H-nutos-4.6.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/determine-compiler-version-enut13H-nutos-4.7.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/determine-compiler-version-enut13H-nutos-4.8.0.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [[Media:Determine-compiler--version-enut13H-nutos-4.8.7.zip|'''Binaries''']]&amp;lt;br&amp;gt;'''Compiler:''' AVR-GCC 4.3.2&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Ethernut 2.1 B&amp;lt;/span&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
| OK&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/determine-compiler-version-enut21B-nutos-4.6.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/determine-compiler-version-enut21B-nutos-4.7.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/determine-compiler-version-enut21B-nutos-4.8.0.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [[Media:Determine-compiler--version-enut21B-nutos-4.8.7.zip|'''Binaries''']]&amp;lt;br&amp;gt;'''Compiler:''' AVR-GCC 4.3.2&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Ethernut 3.0 E&amp;lt;/span&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
| OK&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/determine-compiler-version-enut30E-nutos-4.6.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/determine-compiler-version-enut30E-nutos-4.7.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/determine-compiler-version-enut30E-nutos-4.8.0.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [[Media:Determine-compiler--version-enut30E-nutos-4.8.7.zip|'''Binaries''']]&amp;lt;br&amp;gt;'''Compiler:''' AVR-GCC 4.3.2&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;EIR 1.0 C&amp;lt;/span&amp;gt;&lt;br /&gt;
| Set jumper JP1 to DEBUG mode.&lt;br /&gt;
| OK&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/determine-compiler-version-EIR1C-nutos-4.6.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/determine-compiler-version-EIR1C-nutos-4.7.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/determine-compiler-version-EIR1C-nutos-4.8.0.zip '''Binaries''']&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| id=&amp;quot;compilertd&amp;quot; colspan=&amp;quot;5&amp;quot; |'''Compiler:''' ARM-GCC 4.2.2 ; AVR-GCC 4.3.0&lt;br /&gt;
|&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
&lt;br /&gt;
This example demonstrates how to determine which compiler was used to compile a program and in the case of the GNU C compiler how to display its version.&lt;br /&gt;
&lt;br /&gt;
==Source Code==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;dev/board.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define STRINGIFY_(x) #x&lt;br /&gt;
#define STRINGIFY(x) STRINGIFY_(x)&lt;br /&gt;
&lt;br /&gt;
#if defined(__AVR__)&lt;br /&gt;
#define CPUTYPE &amp;quot;AVR&amp;quot;&lt;br /&gt;
#elif defined (__arm__)&lt;br /&gt;
#define CPUTYPE &amp;quot;ARM&amp;quot;&lt;br /&gt;
#else&lt;br /&gt;
#define CPUTYPE &amp;quot;&amp;quot;&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined(__GNUC__)&lt;br /&gt;
#if defined(__GNUC_PATCHLEVEL__)&lt;br /&gt;
#define COMPILER CPUTYPE &amp;quot;-&amp;quot; &amp;quot;GCC&amp;quot; &amp;quot; &amp;quot; STRINGIFY(__GNUC__) &amp;quot;.&amp;quot; STRINGIFY(__GNUC_MINOR__) &amp;quot;.&amp;quot; STRINGIFY(__GNUC_PATCHLEVEL__)&lt;br /&gt;
#else&lt;br /&gt;
#define COMPILER CPUTYPE &amp;quot;-&amp;quot; &amp;quot;GCC&amp;quot; &amp;quot; &amp;quot; STRINGIFY(__GNUC__) &amp;quot;.&amp;quot; STRINGIFY(__GNUC_MINOR__)&lt;br /&gt;
#endif&lt;br /&gt;
#elif defined (__IMAGECRAFT__)&lt;br /&gt;
#define COMPILER &amp;quot;ICCAVR&amp;quot;&lt;br /&gt;
#else&lt;br /&gt;
#define COMPILER &amp;quot;Unknown&amp;quot;&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
    u_long baud = 115200;&lt;br /&gt;
&lt;br /&gt;
    NutRegisterDevice(&amp;amp;DEV_DEBUG, 0, 0);&lt;br /&gt;
    freopen(DEV_DEBUG_NAME, &amp;quot;w&amp;quot;, stdout);&lt;br /&gt;
    _ioctl(_fileno(stdout), UART_SETSPEED, &amp;amp;baud);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Compiler: %s\n&amp;quot;, COMPILER);&lt;br /&gt;
&lt;br /&gt;
    for(;;);&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Output==&lt;br /&gt;
&lt;br /&gt;
 Compiler: ARM-GCC 4.2.2&lt;br /&gt;
&lt;br /&gt;
==Details==&lt;br /&gt;
&lt;br /&gt;
The main action takes place in the preprocessor commands as you can see.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define STRINGIFY_(x) #x&lt;br /&gt;
#define STRINGIFY(x) STRINGIFY_(x)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These lines are required to store an integer value in a string.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#if defined(__AVR__)&lt;br /&gt;
#define CPUTYPE &amp;quot;AVR&amp;quot;&lt;br /&gt;
#elif defined (__arm__)&lt;br /&gt;
#define CPUTYPE &amp;quot;ARM&amp;quot;&lt;br /&gt;
#else&lt;br /&gt;
#define CPUTYPE &amp;quot;&amp;quot;&lt;br /&gt;
#endif&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This block of code checks if the current board uses an AVR or an ARM processor.&lt;br /&gt;
It makes use of the macros &amp;lt;code&amp;gt;__AVR__&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;__arm__&amp;lt;/code&amp;gt; , which are defined, if the corresponding CPU is installed.&lt;br /&gt;
The new macro &amp;lt;code&amp;gt;CPUTYPE&amp;lt;/code&amp;gt; now is defined as &amp;lt;code&amp;gt;ARM&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;AVR&amp;lt;/code&amp;gt;. &lt;br /&gt;
Before calling the &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; function, the preprocessor substitutes &amp;lt;code&amp;gt;CPUTYPE&amp;lt;/code&amp;gt; by &amp;lt;code&amp;gt;ARM&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;AVR&amp;lt;/code&amp;gt;&lt;br /&gt;
So, whenever we use &amp;lt;code&amp;gt;CPUTYPE&amp;lt;/code&amp;gt; in our program we get either an &amp;lt;code&amp;gt;&amp;quot;ARM&amp;quot;&amp;lt;/code&amp;gt; or an &amp;lt;code&amp;gt;&amp;quot;AVR&amp;quot;&amp;lt;/code&amp;gt; string.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#if defined(__GNUC__)&lt;br /&gt;
#if defined(__GNUC_PATCHLEVEL__)&lt;br /&gt;
#define COMPILER CPUTYPE &amp;quot;-&amp;quot; &amp;quot;GCC&amp;quot; &amp;quot; &amp;quot; STRINGIFY(__GNUC__) &amp;quot;.&amp;quot; STRINGIFY(__GNUC_MINOR__) &amp;quot;.&amp;quot; STRINGIFY(__GNUC_PATCHLEVEL__)&lt;br /&gt;
#else&lt;br /&gt;
#define COMPILER CPUTYPE &amp;quot;-&amp;quot; &amp;quot;GCC&amp;quot; &amp;quot; &amp;quot; STRINGIFY(__GNUC__) &amp;quot;.&amp;quot; STRINGIFY(__GNUC_MINOR__)&lt;br /&gt;
#endif&lt;br /&gt;
#elif defined (__IMAGECRAFT__)&lt;br /&gt;
#define COMPILER &amp;quot;ICCAVR&amp;quot;&lt;br /&gt;
#else&lt;br /&gt;
#define COMPILER &amp;quot;Unknown&amp;quot;&lt;br /&gt;
#endif&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This segment of code consists of 2 nested &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statements, to determine, which compiler was used.&lt;br /&gt;
Aditionally, if GNUC (GCC) was used, which version was used.&lt;br /&gt;
&lt;br /&gt;
To do so, these 4 predefined macros are used.&lt;br /&gt;
* __GNUC__    - Gets replaced by the major version number. (here: 4) Only defined if GCC was used as compiler.&lt;br /&gt;
* __GNUC_MINOR__    - Gets replaced by the minor version number. (here: 2)&lt;br /&gt;
* __GNUC_PATCHLEVEL__    - Gets replaced by the patchlevel (thrid position) version number (here: 2)&lt;br /&gt;
* __IMAGECRAFT__    - Is defined if ICCAVR was used to compile.&lt;br /&gt;
&lt;br /&gt;
So macros are not only used to be replaced by certain values, but also just to check if they were defined or not.&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define STRINGIFY_(x) #x&lt;br /&gt;
#define STRINGIFY(x) STRINGIFY_(x)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
defined&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define COMPILER CPUTYPE &amp;quot;-&amp;quot; &amp;quot;GCC&amp;quot; &amp;quot; &amp;quot; STRINGIFY(__GNUC__) &amp;quot;.&amp;quot; STRINGIFY(__GNUC_MINOR__) &amp;quot;.&amp;quot; STRINGIFY(__GNUC_PATCHLEVEL__)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
we can now use a macro &amp;quot;function&amp;quot; (&amp;lt;code&amp;gt;STRINGIFY&amp;lt;/code&amp;gt;) to define a macro (&amp;lt;code&amp;gt;COMPILER&amp;lt;/code&amp;gt;) as a string  to contain integer values like &amp;lt;code&amp;gt;__GNUC__&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;(_GNUC_MINOR__&amp;lt;/code&amp;gt; do.&lt;br /&gt;
&lt;br /&gt;
In other words, &amp;lt;code&amp;gt;STRINGIFY&amp;lt;/code&amp;gt; turns its parameter into a string value. These string values as well as some dots and the &amp;lt;code&amp;gt;CPUTYPE&amp;lt;/code&amp;gt; macro (which &amp;quot;holds&amp;quot; a string already) replace &amp;lt;code&amp;gt;COMPILER&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
printf(&amp;quot;Compiler: %s\n&amp;quot;, COMPILER);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So everytime we use &amp;lt;code&amp;gt;COMPILER&amp;lt;/code&amp;gt; in our program, we get a string instead, which holds the compiler name and version.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Determine Nut/OS Version]]&lt;br /&gt;
* [[Determine Application Version]]&lt;br /&gt;
* More [[Nut/OS Examples]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Code Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Languages}}&lt;/div&gt;</summary>
		<author><name>AdrianPyka</name></author>	</entry>

	</feed>