Phobos examples and auto

Marco Leise Marco.Leise at gmx.de
Tue Nov 8 08:25:57 PST 2011


Am 07.11.2011, 18:36 Uhr, schrieb Jonathan M Davis <jmdavisProg at gmx.com>:

> 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

After some hacking into the keyboard layout file, I now use the alias ℕ  
(the mathematical symbol for the non-negative integral number) everywhere  
instead of the ugly size_t. It is even shorter than 'auto'.

ℕ i = 5;
ℕ j = i;
ℕ k = j;
ℕ l = k;

;)


More information about the Digitalmars-d mailing list