From -3677996757097076956
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f78e5,290ced9644daa112
X-Google-Attributes: gidf78e5,public
From: jkanze@otelo.ibmmail.com
Subject: Re: Types with Bit-Sizes
Date: 1998/03/17
Message-ID: <6ejmcr$e24$1@nnrp1.dejanews.com>#1/1
X-Deja-AN: 334712814
Content-Transfer-Encoding: quoted-printable
References: <35084BDC.4108978E@verisim.com> <paul-1303981134270001@206.169.118.19>
X-Original-Date: Mon, 16 Mar 1998 11:11:38 -0600
Content-Type: text/plain; charset=iso-8859-1
X-Http-User-Agent: Mozilla/4.03 [de] (WinNT; I)
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Mon Mar 16 17:11:38 1998 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANQ2/OOEDnX0m9pzZAQEcCgF+MybtZQIki9XcjNx8+a+onpgzXBaPzdau WLoJzDFAsngabR2zpim42YwvTH0vcxue =Q8i6
MIME-Version: 1.0
X-MIME-Autoconverted: from 8bit to quoted-printable by ncar.UCAR.EDU id KAA29942
Newsgroups: comp.std.c++


In article <paul-1303981134270001@206.169.118.19>,
  paul@mbed.com (Paul Hamilton) wrote:
>
> In article <35084BDC.4108978E@verisim.com>, Brian White
> <bcwhite@verisim.com> wrote:
>
> > Is there anything in the the ANSI C++ spec that provides for datatype=
s of
> > known bit sizes?
> >
> > If not, could such a thing be added?  Such a thing is really needed w=
hen
> > making data structures that can be moved across machines.
> >
> > In the past, I've used the following conventions and found they work
> > very well.
> >
> > typedef UINT32  ...;    // an unsigned integer of _exactly_ 32 bits
> > typedef SINT32  ...;    // a signed integer of _exactly_ 32 bits
> > typedef uint32  ...;    // an unsigned integer of _at_least_ 32 bits
> > typedef sint32  ...;    // a signed integer of _at_least_ 32 bits
> >
> > The "uint32" would be defined as a the type optimial for that compile=
r
> > that was a minimum of 32 bits long.  A "uint8" would probably be an
> > "unsigned char" while "sint16" and "sint32" would just be "int" (on a
> > 32-bit machine, of course).
> >
> > Of course, there are UINT16, SINT8, uint64, etc., as well.  I've also
> > defined FLOAT32, FLOAT64, float32, and float64 types using the same
> > conventions.
> >
>
> This get's mentioned quite often around C++, but the reality is that
> passing structs between machines is a really bad idea.

Except that his UINT16, etc. are not structs, but basic data types.
Of course, there is still the problem of byte order, signed representatio=
n,
and what to do if bytes aren't 8 bits.  While the latter two are pretty
exotic (although implementations exist), byte order can't be ignored.

Of course, such definitions for float's are completely useless, given
the wide variation in floating point formats.

> The best way to achieve compatibility is to override your objects with
> serialize methods (or use streams) to put and get the data.

Again: how do you override a function on int.

> Relying on bit/byte size, or even the fact that structures will actuall=
y
> stay the same size, with members in the same positions between revs of
> compilers/code bases is not realistic.

I think that you can probably rely on the things determined by hardware,
like the representation of negative numbers, or the number of bits in
a byte, not changing.  That's about it, though.

--
James Kanze    +33 (0)1 39 23 84 71    mailto: kanze@gabi-soft.fr
        +49 (0)69 66 45 33 10    mailto: jkanze@otelo.ibmmail.com
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique orient=E9e objet --
              -- Beratung in objektorientierter Datenverarbeitung

-----=3D=3D Posted via Deja News, The Leader in Internet Discussion =3D=3D=
-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



