To avoid some 32=>64 bit user code port bugs
Adam Ruppe
destructionator at gmail.com
Mon Aug 16 07:55:56 PDT 2010
On 8/16/10, bearophile <bearophileHUGS at lycos.com> wrote:
> So I think size_t=>uint may require a cast on 32
> bit systems too, so when the code gets compiled with the 64 bit dmd this
> error isn't present.
I don't think that's a good idea because of what you say later in your
post: the cast punches a hole through the system. On 32 bit, the cast
is certainly safe, but on 64 bit, it might not be, but the compiler
won't complain.
I think right now, size_t is an alias to uint. On 64 bit, it'll
probably be an alias to ulong. That means assigning to uint won't
compile, so it draws your attention to the line. You can look it over
and decide if the cast is actually warranted or not.
If you put the cast there in 32 bit, it will work and might silently
break it later in 64 bit.
Casts should be avoided whenever possible. Every required cast is
another potential silent bug down the line.
> So 64 bit DMD may show a warning for pointer=>uint casts, I don't know.
That's probably a good idea.
More information about the Digitalmars-d
mailing list