<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>struct inititalization in C and in C++</title>
		<link>http://www.allegro.cc/forums/view/613599</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 05 Dec 2013 06:28:28 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey, I have this code which won&#39;t compile. The first half I guess would work in C, but it does not work in C++. The second way almost works, but the order of the parameters is wrong and since ALLEGRO_VERTEX is an opaque structure it might change, and I don&#39;t know the correct order anyway.</p><div class="source-code snippet"><div class="inner"><pre><span class="c">/*</span>
<span class="c">   ALLEGRO_VERTEX quad[4] = {// counterclockwise from top left</span>
<span class="c">      {.x = viewdrawx             , .y = viewdrawy              , .z = 0.0 , .color = white , .u = texlx , .v = texty},</span>
<span class="c">      {.x = viewdrawx             , .y = viewdrawy + viewheight , .z = 0.0 , .color = white , .u = texlx , .v = texby},</span>
<span class="c">      {.x = viewdrawx + viewwidth , .y = viewdrawy + viewheight , .z = 0.0 , .color = white , .u = texrx , .v = texby},</span>
<span class="c">      {.x = viewdrawx + viewwidth , .y = viewdrawy              , .z = 0.0 , .color = white , .u = texrx , .v = texty}</span>
<span class="c">   };</span>
<span class="c">//*/</span>
   <a href="http://www.allegro.cc/manual/ALLEGRO_VERTEX"><span class="a">ALLEGRO_VERTEX</span></a> quad<span class="k2">[</span><span class="n">4</span><span class="k2">]</span> <span class="k3">=</span> <span class="k2">{</span><span class="c">// counterclockwise from top left</span>
      <span class="k2">{</span>viewdrawx             , viewdrawy              , <span class="n">0</span>.<span class="n">0</span> , <span class="k2">{</span>white<span class="k2">}</span> , texlx , texty<span class="k2">}</span>,
      <span class="k2">{</span>viewdrawx             , viewdrawy <span class="k3">+</span> viewheight , <span class="n">0</span>.<span class="n">0</span> , <span class="k2">{</span>white<span class="k2">}</span> , texlx , texby<span class="k2">}</span>,
      <span class="k2">{</span>viewdrawx <span class="k3">+</span> viewwidth , viewdrawy <span class="k3">+</span> viewheight , <span class="n">0</span>.<span class="n">0</span> , <span class="k2">{</span>white<span class="k2">}</span> , texrx , texby<span class="k2">}</span>,
      <span class="k2">{</span>viewdrawx <span class="k3">+</span> viewwidth , viewdrawy              , <span class="n">0</span>.<span class="n">0</span> , <span class="k2">{</span>white<span class="k2">}</span> , texrx , texty<span class="k2">}</span>
   <span class="k2">}</span><span class="k2">;</span>
</pre></div></div><p>


What&#39;s the best way to initialize an opaque C struct in C++?</p><p>Edit<br />I like this option :</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Option D:</p><div class="source-code snippet"><div class="inner"><pre>FooBar FooBarMake<span class="k2">(</span><span class="k1">int</span> foo, <span class="k1">float</span> bar<span class="k2">)</span>
</pre></div></div><p>

Legal C, legal C++. Easily optimizable for PODs. Of course there are no named arguments, but this is like all C++. If you want named arguments, Objective C should be better choice.
</p></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 04 Dec 2013 10:40:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_VERTEX"><span class="a">ALLEGRO_VERTEX</span></a></span> is not opaque.</p><p>This should be ok: <span class="source-code"><span class="k2">{</span>x, y, z, u, v, color<span class="k2">}</span></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Wed, 04 Dec 2013 11:46:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>As for opaque types, IMO there needs to be a public API, or else you aren&#39;t supposed to touch it. You should never directly access an opaque structure. Your only access to it should be through the API.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Wed, 04 Dec 2013 12:00:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/613599/993590#target">SiegeLord</a> said:</div><div class="quote"><p>
ALLEGRO_VERTEX is not opaque.
</p></div></div><p>
How do you know when a struct is opaque?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
This should be ok: {x, y, z, u, v, color}. 
</p></div></div><p>
The manual documents them in the order x, y, z, color, u, v. It&#39;s kind of misleading.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 05 Dec 2013 03:33:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/613599/993617#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> How do you know when a struct is opaque?</p></div></div><p>If it were truly opaque, there&#39;d be no include file available to user programs to say what the members were.  Some interfaces aren&#39;t really opaque, such as stdio, but if you don&#39;t treat them as such you&#39;re in for a lot of pain.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 05 Dec 2013 03:36:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Allegro has some opaque types. the header only declares:</p><p><span class="source-code"><span class="k1">struct</span> ALLEGRO_FOO<span class="k2">;</span></span></p><p>so you can&#39;t access anything inside it. An internal header will define the structure for allegro internal code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 05 Dec 2013 03:44:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/613599/993617#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> How do you know when a struct is opaque?
</p></div></div><p>If this code compiles: <span class="source-code">Struct a<span class="k2">;</span></span> then <span class="source-code">Struct</span> is not opaque.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> The manual documents them in the order x, y, z, color, u, v. It&#39;s kind of misleading.</p></div></div><p>This has now been fixed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 05 Dec 2013 06:02:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for fixing the docs.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 05 Dec 2013 06:28:28 +0000</pubDate>
	</item>
</rss>
