Re: Moving from C++ to VC++
- From: "Hendrik Schober" <SpamTrap@xxxxxx>
- Date: Mon, 13 Jun 2005 12:51:23 +0200
Doug Harrison [MVP] <dsh@xxxxxxxx> wrote:
> On Fri, 10 Jun 2005 10:20:34 +0200, Hendrik Schober wrote:
>
> >> Portable code can't assume long is larger than 32 bits. If you care about
> >> anything beyond the minimum sizes, you have no business using the native
> >> types.
> >
> > By the same resoning, it can't assume 'long' to
> > be 32bits. Yet this was named as the reason for
> > 'long' being 32bits on a 64bits platform.
>
> The 32 bit long choice for Win64 was a consideration for backward
> compatibility, not some abstract notion of portability. [...]
'long' being 32bits wasn't guaranteed earlier,
so it isn't needed for backwards compatibility.
> When I put on my purist cap, if I accept 32 bit ints, I don't see any
> particular reason to _make_ long 64 bits on a 64 bit platform, because a 32
> bit long is all that's required.
Of course, it's not required to be 64bit.
However, I would expect that at least the
biggest of the std integer type would use the
native integer size of the underlying hardware.
(Actually, I would even expect 'int' to be
this.)
> [...]
> I guess you're more a purist than the rest of us. [...]
Why? Because I raised the question how long
we're going to sit on 32bit because of
compatibility with code that should have
never been written to need this?
If compiler writers would always have
taken broken code into account, we would
probably still sit on 8bit 'int'.
> >>> (Even though I would prefer 'int' to be the
> >>> native integer type of the platform. If you need
> >>> less than that, use 'short' or 'int32_t' or
> >>> whatever.)
>
> There's no guarantee short is smaller than int, [...]
No, there isnt'. If I need "rather small
integers" only, I'll still use it for
certain definitions of "rather small".
(Like in the range -100 < x < 100.) If I
need 32bits, I can use 'int32_t'.
> [...] Not to mention, your "no
> excuse" comment about 64 bit longs suggests you might use it non-portably
> if it were available to you. I mean, if you're such a portable guy, why
> would you even care about this?
Because now I have to use '__int64'?
> There are many subtle ways non-portable assumptions creep into code. Here's
> one. In your 32 bit programming, if you've ever used int to represent a
> size, index, or anything having to do with capacity in a data structure,
> loop index, etc, and your users can reasonably expect to work with data
> sets containing more than 32,767 items, you might have been non-portable.
Right. That's why I don'T use it for this.
> Here's another. If you've ever written code that cannot work in a 16 bit
> (non-VM) address space, perhaps due to large auxiliary data structures it
> needs to function, you might have been non-portable.
I don't know if our code runs on 16bit. (And
I don't care. I don't think any of our code
will ever be ported to a 16bit platform.) If
this should ever become a problem, I expect
the usual amount of work necessary for porting
to a platform with uncommon characteristics:
It dips your nose right into the places where
you've made stupid assumptions. Usually, the
code is better after you ported it.
Schobi
--
SpamTrap@xxxxxx is never read
I'm Schobi at suespammers dot org
"Coming back to where you started is not the same as never leaving"
Terry Pratchett
.
- Follow-Ups:
- Re: Moving from C++ to VC++
- From: Doug Harrison [MVP]
- Re: Moving from C++ to VC++
- References:
- Moving from C++ to VC++
- From: NoName
- Re: Moving from C++ to VC++
- From: Severian [MVP]
- Re: Moving from C++ to VC++
- From: Victor Bazarov
- Re: Moving from C++ to VC++
- From: Carl Daniel [VC++ MVP]
- Re: Moving from C++ to VC++
- From: Hendrik Schober
- Re: Moving from C++ to VC++
- From: Carl Daniel [VC++ MVP]
- Re: Moving from C++ to VC++
- From: Hendrik Schober
- Re: Moving from C++ to VC++
- From: Doug Harrison [MVP]
- Re: Moving from C++ to VC++
- From: Hendrik Schober
- Re: Moving from C++ to VC++
- From: Doug Harrison [MVP]
- Moving from C++ to VC++
- Prev by Date: Re: Training CDs
- Next by Date: Re: Confusion about integer promotions.
- Previous by thread: Re: Moving from C++ to VC++
- Next by thread: Re: Moving from C++ to VC++
- Index(es):
Relevant Pages
|