Re: Moving from C++ to VC++



Doug Harrison [MVP] <dsh@xxxxxxxx> wrote:
> [...]
> > But I really don't see any excuse for not making
> > 'long' 64bit on a 64bit platform.
>
> Portable code can't assume long is larger than 32 bits.

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.

> If you care about
> anything beyond the minimum sizes, you have no business using the native
> types. I know we all violated that with int and 32 bit platforms [...]

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 can't remember the last time I wrote "long" on a 32 bit platform,
> where I know int is 32 bits, and long is the same size. Well, that's not
> entirely true. Like a lot of people, I assumed size_t would fit in an
> unsigned long when using printf and friends and cast accordingly. [...]

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.

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


.



Relevant Pages

  • Re: Moving from C++ to VC++
    ... >> Portable code can't assume long is larger than 32 bits. ... directed to purists who don't care about invalidating existing code. ... There's no guarantee short is smaller than int, and we're back to what I ... said about portable code and minimum sizes. ...
    (microsoft.public.vc.language)
  • Re: If you could change the C or C++ or Java syntax, what would you like different?
    ... int are the same type -- there's no way I could use that information ... That really sums it up on the technical side. ... understandable and portable code. ... ¹ There are corner cases like the 'reference types' I already mentioned ...
    (comp.lang.c)
  • Re: Delay Routine: Fully-portable C89 if possible
    ... Perhaps you were on about "long long unsigned int"? ... If the compiler doesn't accept ... then it isn't a C89 compiler. ... Since the OP was asking for portable code in an embedded newsgroup, there's no way he can make assumptions about the size of "int". ...
    (comp.arch.embedded)
  • Re: Sizes of Integer Types
    ... "Kelsey Bjarnason" wrote in message ... you need to write 100% portable code, ... can't do that because the types you could use to pull this off can't be ... If I want to write code that is only portable to systems that have a 32-bit integer type, then the easiest way to get that data type is to use int32_t. ...
    (comp.lang.c)
  • Re: [OT] Re: switch { } - case for range
    ... portable code is clearer: ... Too bad C didn't keep the range syntax from BCPL. ... int main ...
    (comp.lang.c)