<?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>Typedef __xxx struct? Defines?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/29748/typedef-__xxx-struct-defines</link><description> 
Hi guys, 

 
I have a piece of code that I copied from another source but I
don&amp;#39;t understand what it means and the Keil compiler doesn&amp;#39;t
either. 

 
The code looks like that: 

 
#if _MSC_VER &amp;gt;= 1000
 #define __CIFx_PACKED_PRE
#endif

typedef __CIFx_PACKED_PRE</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Typedef __xxx struct? Defines?</title><link>https://community.arm.com/thread/130904?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2011 03:06:20 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0ddb5013-a652-47d0-bacb-a6972672b3f5</guid><dc:creator>Susan Ferra</dc:creator><description>&lt;p&gt;&lt;p&gt;
sorry: what I meant by &amp;#39;argument&amp;#39; was &amp;lt;name&amp;gt;.&lt;/p&gt;

&lt;p&gt;
So what I actually wanted to state to verify my understanding
was:&lt;/p&gt;

&lt;p&gt;
If there is just a name and no expansion data in the #define, then
the compiler will just remove that name in the sourcecode while
preprocessing.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Typedef __xxx struct? Defines?</title><link>https://community.arm.com/thread/127228?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2011 01:56:52 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8f85eab7-12e5-42de-a10a-ce58beba581e</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
One argument?&lt;/p&gt;

&lt;p&gt;
No #define &amp;lt;name&amp;gt; &amp;lt;expansion data&amp;gt;&lt;/p&gt;

&lt;p&gt;
or #define &amp;lt;name&amp;gt; (&amp;lt;arg&amp;gt;[,&amp;lt;arg&amp;gt;]) &amp;lt;expansion
data&amp;gt;&lt;/p&gt;

&lt;p&gt;
A #define always has a name of the defined symbol.&lt;br /&gt;
Then an optional list of arguments.&lt;br /&gt;
Then what the #define should expand to - and it&amp;#39;s allowed to have
empty defines that does not have any expansion data.&lt;/p&gt;

&lt;p&gt;
Remember that #define is a preprocessor concept. It&amp;#39;s a glorified
search/replace that is done on-the-fly before the compiler processes
the source code.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Typedef __xxx struct? Defines?</title><link>https://community.arm.com/thread/116598?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2011 01:17:26 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:37ba86af-373d-4ff7-b213-1179f5f6b683</guid><dc:creator>Susan Ferra</dc:creator><description>&lt;p&gt;&lt;p&gt;
So if a define has only one argument the compiler will remove this
in the code.&lt;br /&gt;
That&amp;#39;s good to know and yes: I will read my textbook again. It&amp;#39;s has
been a while since I looked into it last time. Thanks Per and
Andrew!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Typedef __xxx struct? Defines?</title><link>https://community.arm.com/thread/105516?ContentTypeID=1</link><pubDate>Thu, 24 Nov 2011 12:22:05 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1b9292a6-3675-4698-b3c6-d837aed604fe</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Some compilers have extra keywords outside the language
standard.&lt;/p&gt;

&lt;p&gt;
So for some operating systems, you may have to use these extra
keywords as attributes to get the compiler to generate special code -
maybe for a calling convention used by the OS.&lt;/p&gt;

&lt;p&gt;
In that case, the preprocessor may check what environment the code
is compiled for. If compiled for an environment where this extra
attribute is needed, then the code has a&lt;/p&gt;

&lt;pre&gt;
#if defined(SPECIAL_CALLING_CONVENTION)
  #define MY_CALLING_CONVENTION_KEYWORD __bloody_fast_call
#else
  #define MY_CALLING_CONVENTION_KEYWORD
#endif

...

void MY_CALLING_CONVENTION the_function(void) {
}
&lt;/pre&gt;

&lt;p&gt;
On an environment where SPECIAL_CALLING_CONVENTION is defined, the
compiler will see:&lt;/p&gt;

&lt;pre&gt;
void __bloody_fast_call the_function(void) {
}
&lt;/pre&gt;

&lt;p&gt;
On an environment where SPECIAL_CALLING_CONVENTION isn&amp;#39;t defined,
the compiler will see:&lt;/p&gt;

&lt;pre&gt;
void the_function(void) {
}
&lt;/pre&gt;

&lt;p&gt;
If checking around, you could find Microsoft include files where
function prototypes looks like:&lt;/p&gt;

&lt;pre&gt;
WINBASEAPI
DWORD
WINAPI
GetCurrentThreadId(
    VOID
    );
&lt;/pre&gt;

&lt;p&gt;
So WINBASEAPI and WINAPI can expand to target-specific extra
goodies when needed.&lt;/p&gt;

&lt;p&gt;
And you might be able to find things like:&lt;/p&gt;

&lt;pre&gt;
/* Define __cdecl for non-Microsoft compilers */

#if     ( !defined(_MSC_VER) &amp;amp;&amp;amp; !defined(__cdecl) )
#define __cdecl
#endif

/* Define _CRTAPI1 (for compatibility with the NT SDK) */

#ifndef _CRTAPI1
#if     _MSC_VER &amp;gt;= 800 &amp;amp;&amp;amp; _M_IX86 &amp;gt;= 300
#define _CRTAPI1 __cdecl
#else
#define _CRTAPI1
#endif
#endif
&lt;/pre&gt;

&lt;p&gt;
In your case, the issue was a structure. In the general case, it&amp;#39;s
the compiler that &amp;quot;owns&amp;quot; the memory layout of a struct. So the
compiler may have one or more specific attributes to allow a user to
select a specific packing for the structure. Should it be packed for
maximum speed, with potentially a lot of padding between fields to
make sure that things match up depending on data type sizes and maybe
even in modulo relation to processor cache line sizes.&lt;/p&gt;

&lt;p&gt;
Or maybe the compiler should pack all struct members to smallest
size, with zero padding even if that makes all members larger than 1
potentially misaligned.&lt;/p&gt;

&lt;p&gt;
Or maybe the compiler has a pack attribute to select pack to
16-bit or 32-bit align.&lt;/p&gt;

&lt;p&gt;
Your sample code looks like it was written to take into account
some such special packing instruction depending on what compiler that
was used.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Typedef __xxx struct? Defines?</title><link>https://community.arm.com/thread/119560?ContentTypeID=1</link><pubDate>Thu, 24 Nov 2011 11:06:28 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a72bb3e2-26da-4152-9d91-a2677098fae8</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;I always thought that defines have to be followed by a number
or something&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
You need to go back to your &amp;#39;C&amp;#39; textbook and review the chapter on
#defines!&lt;/p&gt;

&lt;p&gt;
Some suggested resources here: &lt;a href="http://blog.antronics.co.uk/2010/12/12"&gt;blog.antronics.co.uk/.../12&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
It is perfectly valid (and, as seen here, quite common) to have a
#define symbol that expands to &lt;b&gt;&lt;i&gt;nothing&lt;/i&gt; at all&lt;/b&gt;!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Typedef __xxx struct? Defines?</title><link>https://community.arm.com/thread/105512?ContentTypeID=1</link><pubDate>Thu, 24 Nov 2011 07:20:37 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6d0b0c7d-ea0e-4093-836b-70ad25e3d80e</guid><dc:creator>Susan Ferra</dc:creator><description>&lt;p&gt;&lt;p&gt;
sorry, that did help indeed. Thank you! I was wrong.&lt;/p&gt;

&lt;p&gt;
But what does it do:&lt;br /&gt;
just doing a #define blabalba&lt;br /&gt;
I always thought that defines have to be followed by a number or
something...like that:&lt;/p&gt;

&lt;pre&gt;
 #define xyz 16
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Typedef __xxx struct? Defines?</title><link>https://community.arm.com/thread/79784?ContentTypeID=1</link><pubDate>Thu, 24 Nov 2011 07:16:53 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:05cc87e2-24cb-4b92-a5ed-2330e87e4fb3</guid><dc:creator>Susan Ferra</dc:creator><description>&lt;p&gt;&lt;p&gt;
what does strip mean in this case?&lt;br /&gt;
The adding of&lt;/p&gt;

&lt;pre&gt;
#define __CIFx_PACKED_PRE
&lt;/pre&gt;

&lt;p&gt;
somewhere before in the code, hasn&amp;#39;t solved the problem..&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Typedef __xxx struct? Defines?</title><link>https://community.arm.com/thread/79783?ContentTypeID=1</link><pubDate>Thu, 24 Nov 2011 07:15:05 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d96a7b44-ea80-46a3-9745-1028c3f99a50</guid><dc:creator>Susan Ferra</dc:creator><description>&lt;p&gt;&lt;p&gt;
no, that didn&amp;#39;t change anything :)&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Typedef __xxx struct? Defines?</title><link>https://community.arm.com/thread/60110?ContentTypeID=1</link><pubDate>Thu, 24 Nov 2011 06:08:53 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3a56f899-67e1-45b4-b488-1043fb2a4220</guid><dc:creator>Tamiryan Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
Maybe you are missing a&lt;/p&gt;

&lt;pre&gt;
#include &amp;lt;stdint.h&amp;gt;
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Typedef __xxx struct? Defines?</title><link>https://community.arm.com/thread/67086?ContentTypeID=1</link><pubDate>Thu, 24 Nov 2011 06:05:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:68ac24fe-80a8-4814-ae6e-752fa9b5a714</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Strip the #__CIFx_PACKED_PRE word.&lt;/p&gt;

&lt;p&gt;
Or add a&lt;/p&gt;

&lt;pre&gt;
#define __CIFx_PACKED_PRE
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
making the preprocessor strip that word on-the-fly.&lt;/p&gt;

&lt;p&gt;
You need to check Microsoft Visual C++ documentation to figure out
what they intended to do with the additional __CIFx_PACKED_PRE
attribute.&lt;/p&gt;

&lt;p&gt;
Just that the full source code must have had another #define line
somewhere or some versions of Visual C++ must have had that symbol
pre-defined. I would have expected the CIFx_PACKED_PRE symbol to be
expanded to __packed or similar when building for some versions of
VC++.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>