9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "David Leimbach" <leimy2k@gmail.com>
To: 9fans@cse.psu.edu
Subject: [9fans] fun and scary evil C code
Date: Wed, 19 Dec 2007 07:15:09 -0800	[thread overview]
Message-ID: <3e1162e60712190715q3f50d601sd88b1e0c6c74afc8@mail.gmail.com> (raw)

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

I was amused by this:
http://www.steike.com/code/useless/evil-c/

I particularly liked the "internalEndianMagic".

I see this in some XML libs, as well as GMP and other open sourced code.

http://unix.derkeiler.com/Newsgroups/comp.unix.programmer/2005-12/msg00198.html


From:
https://svn.r-project.org/R/trunk/src/extra/trio/trionan.c

/*
 * Endian-agnostic indexing macro.
 *
 * The value of internalEndianMagic, when converted into a 64-bit
 * integer, becomes 0x0706050403020100 (we could have used a 64-bit
 * integer value instead of a double, but not all platforms supports
 * that type). The value is automatically encoded with the correct
 * endianess by the compiler, which means that we can support any
 * kind of endianess. The individual bytes are then used as an index
 * for the IEEE 754 bit-patterns and masks.
 */
#define TRIO_DOUBLE_INDEX(x) (((unsigned char *)&internalEndianMagic)[7-(x)])
static TRIO_CONST double internalEndianMagic = 7.949928895127363e-275;
#endif

pretty weird stuff.

[-- Attachment #2: Type: text/html, Size: 2084 bytes --]

             reply	other threads:[~2007-12-19 15:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-19 15:15 David Leimbach [this message]
2007-12-19 20:37 ` Russ Cox
2007-12-19 22:32   ` Robert William Fuller
2007-12-19 22:38     ` erik quanstrom
2007-12-19 22:51   ` Bakul Shah
2007-12-20  0:18   ` dave.l
2007-12-20  0:33     ` dave.l
2007-12-20  0:51       ` erik quanstrom
2007-12-20  9:29         ` roger peppe
2007-12-20 13:02           ` erik quanstrom
2007-12-20 16:29 Russ Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3e1162e60712190715q3f50d601sd88b1e0c6c74afc8@mail.gmail.com \
    --to=leimy2k@gmail.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).