Re: Moving from C++ to VC++
- From: "Doug Harrison [MVP]" <dsh@xxxxxxxx>
- Date: Fri, 10 Jun 2005 10:41:29 -0500
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. My comment was
directed to purists who don't care about invalidating existing code.
Clearly, such a person shouldn't care what size long is, as long as it
satisfies the requirements for long. In the message I replied to, you
pretty much conceded that 32 bits were OK, but then you went on to say that
you "don't see any excuse for not making 'long' 64bit on a 64bit platform."
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.
> I don't think I have ever assumed anything about
> any of the integer type except for small (100LOC)
> toy programs. (I might have accidently done this,
> but then I'd be happy to have my nose pointed at
> it.)
>
> I haven't done any of those either.
>
> Maybe that's because I started to work for a
> company where all code gets ported to a couple
> of platform shortly after starting to work in
> this field at all. That teaches a lot about
> what you can assume and what you can't.
I guess you're more a purist than the rest of us. Or at least you think you
are. :) Statements like this one from your last post make me wonder:
>>> (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, and we're back to what I
said about portable code and minimum sizes. 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?
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.
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.
--
Doug Harrison
Microsoft MVP - Visual C++
.
- Follow-Ups:
- Re: Moving from C++ to VC++
- From: Hendrik Schober
- 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
- Moving from C++ to VC++
- Prev by Date: new/delete problem with DLLs (using multi-threaded DLL c-runtime)
- Next by Date: Re: Data aligning
- Previous by thread: Re: Moving from C++ to VC++
- Next by thread: Re: Moving from C++ to VC++
- Index(es):
Relevant Pages
|