Board index » cppbuilder » Re: compare structures

Re: compare structures


2007-08-21 06:53:35 AM
cppbuilder84
Asger Jorgensen < XXXX@XXXXX.COM >wrote:
Quote
But what then, about all those structs that are send with messages
There must be a lot of applications that won't work if they chage
the size of an int, don't You think they will invent a new type instead
of changing the int ?
Those structs have specified member sizes, and will usually have things
like int32 or DWORD specified. For over-the-wire, they're also specified
as to byte order, and there are functions like ntoh() to turn a native
(host) 32-bit entity into a network (n) one.
Alan Bellingham
--
Team Browns
<url:www.borland.com/newsgroups/>Borland newsgroup descriptions
<url:www.borland.com/newsgroups/netiquette.html>netiquette
 
 

Re:Re: compare structures

Asger Jorgensen wrote:
Quote
don't You think they will invent a new type instead
of changing the int ?
The size of int has already changed.
It was 16 bits in the days of DOS, and is 32 bits in Windows32.
I suspect it will be 64 bits in Windows64 and 128 bits in Windows128.
Lesson:
Don't use {*word*192} "int" in persistant structures.
 

Re:Re: compare structures

"Hendrik Schober" < XXXX@XXXXX.COM >writes:
Quote
ACE! That rings a bell. I read something just yesterday...
<googles>
Ha!
"ACE is an open source project, so you're free to download it,
look at the source code, and be horrified." Jeff Garland
(www.artima.com/cppsource/boost_con_07.html)

:o>
Ha! That's funny. It's true that ACE is a very old library with some
really ancient ways of doing things, it's monolithic in some of its
design, and the formatting has most files with lines exceeding 100
characters (with the worst exceeding 200 characters).
However, for what it does, there still isn't anything that comes close
to ACE. Boost is just starting to get some ACE-like features, but
it's far, far from complete in terms of all the things ACE offers.
It's actually kind of sad that a modern version of ACE isn't written,
using new C++ idioms, fewer macros, and less inheritance. Ah well.
Who would take on such an endeavor? :)
--
Chris (TeamB);
 

{smallsort}

Re:Re: compare structures

Asger Jorgensen < XXXX@XXXXX.COM >writes:
Quote
But what then, about all those structs that are send with messages
There must be a lot of applications that won't work if they chage
the size of an int, don't You think they will invent a new type instead
of changing the int ?
No. It has already happened before when machines went from 16 to 32
bits. It'll most likely happen again. The C++ standard only requires
that the relative sizes of integral types are at least as large as the
smaller types. That is:
sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof long
Of course, this doesn't say what the sizes ARE, but the standard does
require that sizeof(char) is always 1. But even that is not always
what people think it means, because there actually have been platforms
where sizeof(char) was more than 8 bits. (Supercomputers, for
example, may make ALL types 64 bits.)
--
Chris (TeamB);
 

Re:Re: compare structures

Chris Uzdavinis (TeamB) < XXXX@XXXXX.COM >wrote:
Quote
Asger Jorgensen < XXXX@XXXXX.COM >writes:

>But what then, about all those structs that are send with messages
>There must be a lot of applications that won't work if they chage
>the size of an int, don't You think they will invent a new type instead
>of changing the int ?

No. It has already happened before when machines went from 16 to 32
bits. It'll most likely happen again. The C++ standard only requires
that the relative sizes of integral types are at least as large as the
smaller types. [...]
AFAIK, it also requires that 'int' be the native
integer type of the platform, which would make it
64bit on 64bit machines. Unfortunately, too many
people have assumed 'int' being 32bit to be cast
into stone and annoyingly most vendors of 64bit
compilers therefor have decided to 'int' being a
32bit integer even on 64bit machines.
I consider this a very stupid decision.
Schobi
--
XXXX@XXXXX.COM is never read
I'm HSchober at gmx dot de
"A patched buffer overflow doesn't mean that there's one less way attackers
can get into your system; it means that your design process was so lousy
that it permitted buffer overflows, and there are probably thousands more
lurking in your code."
Bruce Schneier
 

Re:Re: compare structures

"Hendrik Schober" < XXXX@XXXXX.COM >wrote:
Quote
AFAIK, it also requires that 'int' be the native
integer type of the platform, which would make it
64bit on 64bit machines. Unfortunately, too many
people have assumed 'int' being 32bit to be cast
into stone and annoyingly most vendors of 64bit
compilers therefor have decided to 'int' being a
32bit integer even on 64bit machines.
I consider this a very stupid decision.
I agree with you - int is supposed to be the native size.
The slight problem that follows is that of providing the different
integer sizes.
8 bits ->char (we'll assume an octet based machine using ascii here)
16 bits ->short
32 bits ->...
64 bits ->int
64 bits ->long
I'm not sure what the .. name should be. Perhaps 'long short'.
Alan Bellingham
--
Team Browns
ACCU Conference 2008: 2-5 April 2008 - Oxford (probably), UK
 

Re:Re: compare structures

Alan Bellingham < XXXX@XXXXX.COM >wrote:
Quote
"Hendrik Schober" < XXXX@XXXXX.COM >wrote:

>AFAIK, it also requires that 'int' be the native
>integer type of the platform, which would make it
>64bit on 64bit machines. Unfortunately, too many
>people have assumed 'int' being 32bit to be cast
>into stone and annoyingly most vendors of 64bit
>compilers therefor have decided to 'int' being a
>32bit integer even on 64bit machines.
>I consider this a very stupid decision.

I agree with you - int is supposed to be the native size.

The slight problem that follows is that of providing the different
integer sizes.

8 bits ->char (we'll assume an octet based machine using ascii here)
16 bits ->short
32 bits ->...
64 bits ->int
64 bits ->long

I'm not sure what the .. name should be. Perhaps 'long short'.
With some compilers 'wchar_t' might be 16bit. :^>
Seriously, wasn't there some proposal for adding something
like 'std::int8_t', 'std::int16_', 'std::int32_' etc.
(or was it even 'std::int<N>'?) floating around? What
became of this?
IIRC, C99 already has something like it, right?
Quote
Alan Bellingham
Schobi
--
XXXX@XXXXX.COM is never read
I'm HSchober at gmx dot de
"A patched buffer overflow doesn't mean that there's one less way attackers
can get into your system; it means that your design process was so lousy
that it permitted buffer overflows, and there are probably thousands more
lurking in your code."
Bruce Schneier
 

Re:Re: compare structures

Alan Bellingham wrote:
Quote
8 bits ->char (we'll assume an octet based machine using ascii here)
16 bits ->short
32 bits ->...
64 bits ->int
64 bits ->long

I'm not sure what the .. name should be. Perhaps 'long short'.
Perhaps a little more "English-ized": "short long" ;-)
Jon
 

Re:Re: compare structures

"Hendrik Schober" < XXXX@XXXXX.COM >wrote in message
Quote
Seriously, wasn't there some proposal for adding something
like 'std::int8_t', 'std::int16_', 'std::int32_' etc.
(or was it even 'std::int<N>'?) floating around? What
became of this?
IIRC, C99 already has something like it, right?
you can use this C99 header in BDS2006 too,
just #include <stdint.h>
Cheers,
Serge
 

Re:Re: compare structures

"Jonathan Benedicto" < XXXX@XXXXX.COM >writes:
Quote
Alan Bellingham wrote:
>8 bits ->char (we'll assume an octet based machine using ascii
>here) 16 bits ->short
>32 bits ->...
>64 bits ->int
>64 bits ->long
>I'm not sure what the .. name should be. Perhaps 'long short'.

Perhaps a little more "English-ized": "short long" ;-)
Yessssssssss! As a (very) part time C++ instructor, I find it very
important that long short and short long mean different things!
 

Re:Re: compare structures

Hi!
Asger Jorgensen schrieb:
Quote
SizeOf_TC5H01 is a static class member initialized with a
sizeof(TFC5H01); at app start i imagine that is faster then
using a sizeof(TFC5H01) every time I read or write.
"sizeof(TFC5H01)" is faster than a static variable.
Well, "sizeof" yields a "compile time constant" and is the fastest there
is. So a static variable can only be slower, but not faster.
"sizeof(char)" is the same effect as writing "1" instead. It is as fast
as a #defined value.
Frank