Ranges usages

Jonathan M Davis jmdavisProg at gmx.com
Thu Nov 22 18:01:49 PST 2012


On Friday, November 23, 2012 01:52:51 Timon Gehr wrote:
> On 11/22/2012 11:25 AM, monarch_dodra wrote:
> > On Thursday, 22 November 2012 at 06:52:55 UTC, Rob T wrote:
> >> FYI
> >> 
> >> I'm getting these compile errors, must be the compiler flags I'm using?
> > 
> > Must be that bearophile and I are on windows (ergo 32), so "length" is
> > of type "size_t", which is a "uint". This matches the key of the
> > dictionary.
> > 
> > If you are linux, then you are probably 64, and the type of
> > "dictionary.length - 1" gets promoted to ulong, and can't be placed back
> > into the dictionary. I don't think this has anything to do with flags.
> > 
> > Placing a cast here "cast(uint)" would be the correct workaround I think.
> 
> The flag is -m32.

That would be a very poor solution if the problem is that you're trying to 
assign a size_t to a uint. Sure, -m32 will make it compile a 32-bit binary 
which would then work, but well-written code doesn't generally care whether 
it's on a 32-bit or 64-bit machine, so if a variable of type size_t is being 
assigned to anything smaller than long, a cast or std.conv.to would be the 
correct way to handle it. Unless you really have to target a specific 
architecture, writing code which assumes what architecture it's in is 
generally bad practice. It should be as cross-platform as is reasonably 
possible, and D and Phobos are well set up to do that.

- Jonathan M Davis


More information about the Digitalmars-d mailing list