GP2X Standart Library Eksikleri

2 replies · 12,181 views

GP2X Standart Library Eksikleri
Gnostic ya da diğer daha önce GP2X coding ile uğraşmış arkadaşlar, GP2X'in standart C librarylerinde bazı eksikler gözüme çarptı. Örneğin atoi varken itoa yok v.s. sprintf ile işi çözdüm ancak yine de "itoa"nın niye olmadığı ve daha önemlisi başka hangi eksiklerin olduğu kafamı kurcaladı. Böyle bir liste var mıdır? Incompitibility ya da todo list tarzı birşeyler?
GP2X Standart Library Eksikleri
itoa standart olarak c/c++ lib'lerinde yok diye biliyorum ben? yanlis olabilir tabi bu bilgim..
itoa ihtiyacim 1 kez oldu (o da psp icin), onda da snprintf kullandim..
//code: gfoot
char *itoa (int num, char *str, int base)
{
    char *pos = str;
    int digit_value;

    if (num < 0) {
        *pos++ = '-';
        num = -num;
    }

    digit_value = 1;
    while (digit_value*base <= num) digit_value *= base;
    while (digit_value > 0) {
        int digit = num / digit_value;
        num -= digit * digit_value;
        *pos++ = '0' + digit;
        digit_value /= base;
    }
    *pos = '\0';
    return str;
}

EDIT:
[FONT=Courier New]sprintf()[/FONT] is the easiest way to do this in most cases. It may seem odd that [FONT=Comic Sans MS]itoa()[/FONT] is not standard when [FONT=Courier New]atoi()[/FONT] is, but apparently the standards committee felt that the former wasn't as portable as the latter (at least I seem to recall that being part of the reason). Also, whereas [FONT=Courier New]atoi()[/FONT] can return an integer value as a function, [FONT=Courier New]itoa()[/FONT] would need to either take a char buffer to write the values into (as the usual version does), or else allocate a string dynamically and return that (which goes against the general design principles of the standard library, which usually avoids dynamic allocation wherever possible).

Last edited: 2007-05-29 12:04

GP2X Standart Library Eksikleri
Turbo C'den bu yana hep kullandığım bir fonksiyondur ve STDLIB'in içinde yer alır. Standart dışı olduğu bir an için bile aklıma gelmemişti. Bilgi için teşekkürler Gnostic.