Phobos examples and auto

Jonathan M Davis jmdavisProg at gmx.com
Mon Nov 7 09:36:31 PST 2011


On Monday, November 07, 2011 08:55 Steven Schveighoffer wrote:
> On Mon, 07 Nov 2011 11:51:36 -0500, Steve Teale
> 
> <steve.teale at britseyeview.com> wrote:
> > On Mon, 07 Nov 2011 07:17:59 -0500, Steven Schveighoffer wrote:
> >> uint i = 5;
> >> uint j = i;
> >> uint k = j;
> >> uint l = k;
> >> 
> >> If I want to make this code 64-bit aware, I need to change all 4 lines.
> >> If these lines are scattered throughout the code, I have to play the
> >> cyclical compiler game, where I change the first one, then compile,
> >> change the second one, compile, etc.
> > 
> > Steve,
> > 
> > OK, you've uncovered a stark example of my ignorance there. The Types
> > documentation does not as far as I can see mention any differences
> > between a 32 bit and a 64 bit environment. It says simply that a uint is
> > 32 bits unsigned.
> > 
> > What is the change that has to be made in your example?
> 
> Sorry, that is my fault. My example was too devoid of context :)
> 
> Try this instead:
> 
> int[] arr;
> 
> uint i = arr.length;
> ...
> 
> i.e. the change that should be made is uint => size_t.

Yeah, all of those examples would be typed to int. size_t is actually a prime 
example of when you actually need to use the type. The length property on an 
array is one of the few cases where the type will be inferred as size_t.

- Jonathan M Davis


More information about the Digitalmars-d mailing list