Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/tex/local/endian.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


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

typedef struct Endian Endian;
struct Endian {
	ulong val;
	char *name;
};

uchar data[4] = {0x11, 0x22, 0x33, 0x44};

Endian elist[] = {
	0x11223344, "big",
	0x44332211, "little"
};

void
main(void)
{
	char *end;
	ulong l;
	Endian *e;

	end = "unknown";
	l = *(ulong*)data;
	for(e=elist; e<elist+nelem(elist); e++)
		if(e->val == l)
			end = e->name;

	print("%s\n", end);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.