From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <47699C10.5060708@gmail.com> Date: Wed, 19 Dec 2007 17:32:48 -0500 From: Robert William Fuller User-Agent: Thunderbird 2.0.0.6 (X11/20071013) MIME-Version: 1.0 To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Subject: Re: [9fans] fun and scary evil C code References: <20071219203654.3714F1E8C1C@holo.morphisms.net> In-Reply-To: <20071219203654.3714F1E8C1C@holo.morphisms.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Topicbox-Message-UUID: 1cbd2f34-ead3-11e9-9d60-3106f5b1d025 Russ Cox wrote: >> #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 Now THAT's something to be proud of. Especially without comments.