From owner-freebsd-current Fri Oct 27 2:14:36 2000 Delivered-To: freebsd-current@freebsd.org Received: from alpha.dante.org.uk (alpha.dante.org.uk [193.63.211.19]) by hub.freebsd.org (Postfix) with ESMTP id 68A9A37B4CF for ; Fri, 27 Oct 2000 02:14:33 -0700 (PDT) Received: from theta.dante.org.uk ([193.63.211.7]) by alpha.dante.org.uk with esmtp (Exim 3.12 #4) id 13p5Zx-0004yP-00; Fri, 27 Oct 2000 10:13:37 +0100 Received: from localhost ([127.0.0.1] helo=dante.org.uk) by theta.dante.org.uk with esmtp (Exim 3.12 #4) id 13p5Zw-0002oC-00; Fri, 27 Oct 2000 10:13:36 +0100 Message-ID: <39F94740.66FCEB9E@dante.org.uk> Date: Fri, 27 Oct 2000 10:13:36 +0100 From: Konstantin Chuguev Organization: Delivery of Advanced Networking Service to Europe Ltd. X-Mailer: Mozilla 4.75 [en] (X11; U; SunOS 5.6 sun4u) X-Accept-Language: en, ru MIME-Version: 1.0 To: Bruce Evans Cc: Brian Somers , kargl@apl.washington.edu, freebsd-current@FreeBSD.ORG Subject: platform byte order macros? References: Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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[] = { , , ... }; But for more efficient processing I would like to have something like const unsigned char array[] = { _4bytes(, , , ) _1long(, , , ) _2shorts(, , , ) _1long(, , , ) _4bytes(, , , ) ... }; ... 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