From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu Subject: Re: [9fans] fun and scary evil C code From: "Russ Cox" Date: Wed, 19 Dec 2007 15:37:25 -0500 In-Reply-To: <3e1162e60712190715q3f50d601sd88b1e0c6c74afc8@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Message-Id: <20071219203654.3714F1E8C1C@holo.morphisms.net> Topicbox-Message-UUID: 1cb0d78e-ead3-11e9-9d60-3106f5b1d025 > #define TRIO_DOUBLE_INDEX(x) (((unsigned char *)&internalEndianMagic)[7-(x)]) this is actually done in /sys/src/9/port/devcons.c too: static uvlong uvorder = 0x0001020304050607ULL; static uchar* le2vlong(vlong *to, uchar *f) { uchar *t, *o; int i; t = (uchar*)to; o = (uchar*)&uvorder; for(i = 0; i < sizeof(vlong); i++) t[o[i]] = f[i]; return f+sizeof(vlong); } static uchar* vlong2le(uchar *t, vlong from) { uchar *f, *o; int i; f = (uchar*)&from; o = (uchar*)&uvorder; for(i = 0; i < sizeof(vlong); i++) t[i] = f[o[i]]; return t+sizeof(vlong); } presotto wrote the code but said he learned the trick from ken. there, of course, we have a real compiler and don't have to write uvlong constants as floating point numbers (wow that seems fragile). russ