From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <4CD69C49.5090209@gmx.net> Date: Sun, 7 Nov 2010 13:32:09 +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> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [9fans] pcc limitation? Topicbox-Message-UUID: 78c7225a-ead6-11e9-9d60-3106f5b1d025 On 07.11.2010 05:02, Federico G. Benavento wrote: > the syntax (){} is for structures, like (Point){0, 0} or something, > so you don't need the braces there, just the cast > > .writearr = (const unsigned char*)JEDEC_WREN, > writearr should point to a one-member const unsigned char array, and the zeroth element of that array has the value JEDEC_WREN. Your suggested code has different behaviour (it casts a uchar to uchar *): #include #include #define JEDEC_WREN 0x06 struct spi_command { const unsigned char *writearr; }; int main(int argc, char *argv[]) { struct spi_command cmds[] = { { .writearr = (const unsigned char[]){ JEDEC_WREN }, },{ .writearr = (const unsigned char *)JEDEC_WREN, }}; printf("Mine: writearr=%p\n", cmds[0].writearr); printf("Mine: writearr[0]=0x%02hhx\n", cmds[0].writearr[0]); printf("Federico: writearr=%p\n", cmds[1].writearr); printf("Federico: writearr[0]=0x%02hhx\n", cmds[1].writearr[0]); return 0; } Output is: Mine: writearr=0xbf8eb213 Mine: writearr[0]=0x06 Federico: writearr=0x6 Segmentation fault Regards, Carl-Daniel -- http://www.hailfinger.org/