From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <1ebc06ba0079a91546444a93ab21bc65@quintile.net> From: "Steve Simon" Date: Wed, 27 Nov 2013 16:03:52 +0000 To: 9fans@9fans.net MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-ereqcqziobbpoonaqvkyujfeex" Subject: [9fans] compiler bug? Topicbox-Message-UUID: 8c3fbbe2-ead8-11e9-9d60-3106f5b1d025 This is a multi-part message in MIME format. --upas-ereqcqziobbpoonaqvkyujfeex Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Whilst porting some code from the net I came across the attached, rather obscure, code. run as: larch% 8c -D 'STATIC=static' t.c && 8l t.8 && 8.out 78780000 larch% 8c -D 'STATIC=' t.c && 8l t.8 && 8.out 0 I think it is tickling a bug in 8c, though I may be just showing my lack of knowledge of the C standard... anyone any thoughts? -Steve --upas-ereqcqziobbpoonaqvkyujfeex Content-Disposition: attachment; filename=t.c Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit #include #include static uint getdword_n(void *mem, int n) { STATIC uint tmp = 0; switch (n) { case 3: ((uchar*)&tmp)[1] = ((uchar*)mem)[2]; case 2: ((uchar*)&tmp)[2] = ((uchar*)mem)[1]; case 1: ((uchar*)&tmp)[3] = ((uchar*)mem)[0]; default: break; } return tmp; } void main(void) { uint x; char buf[] = "xxxx"; x = getdword_n(buf, 2); print("%x\n", x); } --upas-ereqcqziobbpoonaqvkyujfeex--