<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/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/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>copy assignment not allowed in union</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/29888/copy-assignment-not-allowed-in-union</link><description>I am attempting to do some development using the usbd_hid_generic example peripheral code. I am using some C++ libraries in this project, however there is syntax in the usbd code (specifically in the app_usbd_class_base.h file) that fails to compile.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 30 Jan 2018 18:09:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/29888/copy-assignment-not-allowed-in-union" /><item><title>RE: copy assignment not allowed in union</title><link>https://devzone.nordicsemi.com/thread/118873?ContentTypeID=1</link><pubDate>Tue, 30 Jan 2018 18:09:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cee801fe-fc42-4ee1-a3c4-5af29d1e6dde</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;C++ cannot skip definitions in between.  All definitions above the one that causes the error has to be filled in order.  You can however skip all bellow.  For example :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static const app_usbd_config_t usbd_config = {
    .ev_state_proc = usbd_user_ev_handler
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Will cause the error but :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static const app_usbd_config_t usbd_config = {
    .ev_isr_handler = NULL,
    .ev_state_proc = usbd_user_ev_handler
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;will not.&lt;/p&gt;
&lt;p&gt;for union stuff :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;typedef struct a {
	int z;
	union {
		int b;
		struct {
			uint8_t c;
			uint16_t d;
		} f;
	};
} A;

A x = {
	.z = 0,
	{ .f = {.c = 1, .d = 2} }
};

A y = {
	.z = 0,
	{ .b = 3 }
};
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: copy assignment not allowed in union</title><link>https://devzone.nordicsemi.com/thread/118872?ContentTypeID=1</link><pubDate>Tue, 30 Jan 2018 17:25:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f83f925f-e4c2-44a9-8eed-7abcedebbfb5</guid><dc:creator>nvp</dc:creator><description>&lt;p&gt;I will eventually be using some custom C++ code to communicate with some peripheral devices, but in the context of this question, the problem can be demonstrated without introducing any additional code to the usbd_hid_generic peripheral example.  Some of the code in the original app_usbd_class_base.h is incompatible with the C++ standards as enforced by the arm-none-eabi-g++ compiler.&lt;/p&gt;
&lt;p&gt;In order to work around the problem, I implemented option 2 from my original post. I reverted main back to a C program and I wrote a new wrapper.h and wrapper.cpp to interface the C++ classes in the libraries that I was using.  These wrapper functions took Class::f(x,y,z) and made a C-style function class_f(void* instance, x, y, z) that could bridge the gap. Using extern &amp;quot;C&amp;quot; here provides C-style hooks. Since all calls to the usbd are exclusively in main.c, compiled by gcc, this avoids the problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: copy assignment not allowed in union</title><link>https://devzone.nordicsemi.com/thread/118869?ContentTypeID=1</link><pubDate>Mon, 29 Jan 2018 08:58:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5460b4f-b486-493b-aa5d-281aa31f3f4f</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;@nvp Are the errors just located in app_usbd_class_base.h? Or did you add some custom code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: copy assignment not allowed in union</title><link>https://devzone.nordicsemi.com/thread/118871?ContentTypeID=1</link><pubDate>Fri, 26 Jan 2018 22:37:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04984686-b2b3-4747-8589-6493ea926e80</guid><dc:creator>nvp</dc:creator><description>&lt;p&gt;The USB interface uses a struct, not a class.  The header files themselves include extern &amp;quot;C&amp;quot; declarations as well, but I added a few additional blocks in main.cpp; no difference.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: copy assignment not allowed in union</title><link>https://devzone.nordicsemi.com/thread/118870?ContentTypeID=1</link><pubDate>Fri, 26 Jan 2018 11:26:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d948623c-ffbe-4f87-966b-56a0d054943b</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Can you try to put &lt;code&gt;extern &amp;quot;C&amp;quot; { }&lt;/code&gt; around the USB class instance initialization?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: copy assignment not allowed in union</title><link>https://devzone.nordicsemi.com/thread/118867?ContentTypeID=1</link><pubDate>Thu, 25 Jan 2018 17:20:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a76f45ef-c185-43ca-a067-ebe69791f493</guid><dc:creator>nvp</dc:creator><description>&lt;p&gt;I was using version 6.3.1.  I tried with version 7.2.1 with the same result.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: copy assignment not allowed in union</title><link>https://devzone.nordicsemi.com/thread/118866?ContentTypeID=1</link><pubDate>Thu, 25 Jan 2018 17:00:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc633910-2a86-4ed7-9591-94c6ce76e1c0</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;which compiler version are you using ? have you tried with v6 or v7 ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: copy assignment not allowed in union</title><link>https://devzone.nordicsemi.com/thread/118868?ContentTypeID=1</link><pubDate>Thu, 25 Jan 2018 16:14:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c67b904-a603-4d17-b09e-5a04975c71b4</guid><dc:creator>nvp</dc:creator><description>&lt;p&gt;Same error:
[...]/app_usbd_class_baseh.:674:5: sorry, unimplemented: non-trivial designated initializers not supported&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: copy assignment not allowed in union</title><link>https://devzone.nordicsemi.com/thread/118865?ContentTypeID=1</link><pubDate>Wed, 24 Jan 2018 23:53:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76c823a5-b238-4bb4-afaa-90578be2c2b4</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;set it to -std=gnu++11 or more recent one.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>