view test/bug55.d @ 120:5ce8ab11e75a trunk

[svn r124] Fixed another D vararg + return in ptr bug. Fixed some nested function calls failed to resolve the context ptr.
author lindquist
date Mon, 26 Nov 2007 07:26:21 +0100
parents 70d6113eeb8c
children d9d5d59873d8
line wrap: on
line source

module bug55;

int atoi(char[] s) {
    int i, fac=1;
    bool neg = (s.length) && (s[0] == '-');
    char[] a = neg ? s[1..$] : s;
    foreach_reverse(c; a) {
        i += (c-'0') * fac;
        fac *= 10;
    }
    return !neg ? i : -i;
}

void main()
{
    printf("64213 = %d\n", atoi("64213"));
    printf("-64213 = %d\n", atoi("-64213"));
    assert(atoi("64213") == 64213);
    assert(atoi("-64213") == -64213);
}