From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <4CD6D235.3030704@gmx.net> Date: Sun, 7 Nov 2010 17:22:13 +0100 From: Carl-Daniel Hailfinger User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.23) Gecko/20090410 SUSE/1.1.18-0.1 SeaMonkey/1.1.18 MIME-Version: 1.0 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> References: <4CD5F934.2080705@gmx.net> <4CD69C49.5090209@gmx.net> <9f6f706b0da2fc0b208ad49c097a823b@brasstown.quanstro.net> In-Reply-To: <9f6f706b0da2fc0b208ad49c097a823b@brasstown.quanstro.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [9fans] pcc limitation? Topicbox-Message-UUID: 78d2d1a4-ead6-11e9-9d60-3106f5b1d025 On 07.11.2010 15:46, erik quanstrom wrote: >> writearr should point to a one-member const unsigned char array, and the >> zeroth element of that array has the value JEDEC_WREN. >> > = > it's not clear to me that c99 allows one to declare an unnamed array > and assign a pointer to it in this way except if the array is a char* or > wchar_t*. > > i think the cleanest approach to solving your problem is > to define writeattr as an array, not a uchar*. > The big problem with defining it as an array inside struct spicmd is that writearr has variable length. writearr is a command sent to a SPI chip by a SPI controller. writearr can have any length of 1-1056 bytes. There's also an analogous readarr in struct spi_command (not mentioned in the example to keep it brief) and that one can have any length between 0 and 16777217 (2^24+1) bytes. One variable-length array at the end of a struct is possible, but an array of structs with a variable length array in the struct won't work since you can't compute the offset of individual members of the outer arrray. The only solution I can see is this: #define JEDEC_WREN 0x06 #define JEDEC_SE 0x20 struct spi_command { const unsigned char *writearr; }; int main(int argc, char *argv[]) { const unsigned char writearr_helper1[] = { JEDEC_WREN }; const unsigned char writearr_helper2[] = { JEDEC_SE, 0x01, 0x23, 0x45 }; struct spi_command cmds[] = { { .writearr = writearr_helper1, },{ .writearr = writearr_helper2, }}; /* ... */ } That solution wastes variables and is generally pretty ugly. I still hope we can find a better solution. Regards, Carl-Daniel -- http://www.hailfinger.org/