9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] compiler bug?
@ 2013-11-27 16:03 Steve Simon
  2013-11-27 16:31 ` erik quanstrom
  0 siblings, 1 reply; 11+ messages in thread
From: Steve Simon @ 2013-11-27 16:03 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 364 bytes --]

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

[-- Attachment #2: t.c --]
[-- Type: text/plain, Size: 479 bytes --]

#include <u.h>
#include <libc.h>

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);
}

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-11-27 21:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-27 16:03 [9fans] compiler bug? Steve Simon
2013-11-27 16:31 ` erik quanstrom
2013-11-27 18:07   ` Skip Tavakkolian
2013-11-27 18:38     ` erik quanstrom
2013-11-27 19:24       ` Skip Tavakkolian
2013-11-27 20:34   ` Bakul Shah
2013-11-27 21:18     ` erik quanstrom
2013-11-27 21:29       ` Charles Forsyth
2013-11-27 21:35         ` erik quanstrom
2013-11-27 21:42           ` Charles Forsyth
2013-11-27 20:41   ` Steve Simon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).