A few notes on choosing between Go and D for a quick project
FG via Digitalmars-d
digitalmars-d at puremagic.com
Sat Mar 21 05:06:17 PDT 2015
On 2015-03-19 at 09:41, Walter Bright wrote:
> On 3/18/2015 4:41 PM, Walter Bright wrote:
>> #include <stdbool.h>
>> #include <stdio.h>
>>
>> typedef long T;
>> bool find(T *array, size_t dim, T t) {
>> int i;
>> for (i = 0; i <= dim; i++);
>> {
>> int v = array[i];
>> if (v == t)
>> return true;
>> }
>> }
>
> Bugs:
>
> 1. i should be size_t
> 2. <= should be <
> 3. extraneous ;
> 4. v should be type T
> 5. missing return
Two more things, I believe, but they aren't really internal bugs of find:
a null array or array > 2GB on 32-bit that would cause negative indexing:
assert(array != 0);
assert(dim <= PTRDIFF_MAX);
More information about the Digitalmars-d
mailing list