NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: C portability question



Greg A. Woods; Planix, Inc. wrote:
>       printf("%" PRId64 "\n", (int64_t) var);

Gah!  Not to disagree, because I don't, but my elegance detector just had
a hissy fit.  Why didn't the inventors of off_t consider printf?  Or even
size_t, for that matter?  (Even the above "standard" approach will fail
when off_t is 128 bits.)

When I deal with this stuff, I find myself wondering if we don't need an
updated itoa.  Wouldn't the code be more portable if libc defined e.g., 

        const char * off_ttoa(off_t in, char a[] out);

that returned the address of the output buffer?  At least that would
localize the architectural differences and allow

        char buffer[MAX_AS_STRING_OFF_T+1];
        printf("%s\n", off_ttoa(var, buffer));

Of course, thread local storage would permit dispensing with the second
parameter, making the function easier to use.  

--jkl


Home | Main Index | Thread Index | Old Index