~skeeto/public-inbox

2 2

Re: Test cross-architecture without leaving home

Jeff Johnson <trnsz@pobox.com>
Details
Message ID
<da3b2493-0a60-4bed-a492-1c5b86e418e1@app.fastmail.com>
DKIM signature
pass
Download raw message
Hi skeeto,

Probably late to the party here, but I was reading https://nullprogram.com/blog/2021/08/21/ but I found your test program overly complex.

You could reduce it to the following one-liner:

```c
#include <stdio.h>
#include <limits.h>
int main(void) {
  return printf("%d-bit, %s-endian\n",
    sizeof(void*)*CHAR_BIT, *(char*)(int[]){1}?"little":"big");
}
```

--
Jeffrey H. Johnson
trnsz@pobox.com

Re: Test cross-architecture without leaving home

Details
Message ID
<20241022013425.qrosjmuczhyiwv2s@nullprogram.com>
In-Reply-To
<da3b2493-0a60-4bed-a492-1c5b86e418e1@app.fastmail.com> (view parent)
DKIM signature
missing
Download raw message
Thanks for sharing, Jeff. That's certainly more concise.

Re: Test cross-architecture without leaving home

Jeff Johnson <trnsz@pobox.com>
Details
Message ID
<e1be0676-fb5e-4e31-a1b3-3dd49b80873b@app.fastmail.com>
In-Reply-To
<20241022013425.qrosjmuczhyiwv2s@nullprogram.com> (view parent)
DKIM signature
pass
Download raw message
#include <stdio.h>
#include <limits.h>
int main(void) {
  int n; n = 1;
  return printf("%lu-bit, %s-endian\n",
    sizeof(void*)*CHAR_BIT, *((char*)&n)?"little":"big");
}

… might be better, compatible with C89.

--
Jeffrey H. Johnson
trnsz@pobox.com
Reply to thread Export thread (mbox)