Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Oct 2000 10:13:36 +0100
From:      Konstantin Chuguev <Konstantin.Chuguev@dante.org.uk>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        Brian Somers <brian@Awfulhak.org>, kargl@apl.washington.edu, freebsd-current@FreeBSD.ORG
Subject:   platform byte order macros?
Message-ID:  <39F94740.66FCEB9E@dante.org.uk>
References:  <Pine.BSF.4.21.0010271755210.47277-100000@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,

AFAICS ntoh[ls] and hton[ls] defined as asm instructions. This prevents
using them in const variables initialisation.
I need to create a const unsigned char array[] (C source file) from quite
a big network byte ordered binary data. Although the data consists mainly
of bytes and 16- and 32-bit words, it is difficult in my case to use
u_char, u_int16_t and u_int32_t, as the order and the number of each type
does not fit to any possible C struct declaration.
Well, I can just create a network ordered byte array C declaration like
const unsigned char array[] = { <byte0>, <byte1>, ... };
But for more efficient processing I would like to have something like
const unsigned char array[] = {
_4bytes(<b0>, <b1>, <b2>, <b3>)
_1long(<b4>, <b5>, <b6>, <b7>)
_2shorts(<b8>, <b9>, <b10>, <b11>)
_1long(<b12>, <b13>, <b14>, <b15>)
_4bytes(<b16>, <b17>, <b18>, <b19>)
...
};
... i.e. platform independent source code which would compile into
platform dependent object file. _4bytes, _2shorts and _1long are macros
produced for byte sequence in appropriate byte order. The macros need to
know the platform byte order, theoretically it can be one of 1234, 4321,
2143.
In endian.h I can see just huge line of comparisons to *_386 et. al., but
I cannot find any macros clearly decsribing the byte order. Am I wrong?

Thanks,
    Konstantin.


--
          * *        Konstantin Chuguev - Application Engineer
       *      *              Francis House, 112 Hills Road
     *                       Cambridge CB2 1PQ, United Kingdom
 D  A  N  T  E       WWW:    http://www.dante.net





To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?39F94740.66FCEB9E>