Re: [Libclc-developers] clc_ultostr(3)
Status: Planning
Brought to you by:
augestad
|
From: <bo...@me...> - 2003-03-20 19:10:17
|
Hallvard B Furuseth wrote: > Bjørn Augestad writes: > >> char *sp = ptr + size - 1; >> >> clc_assert_not_null(clc_ultostr, ptr); >> clc_assert_arg(clc_ultostr, size > 1); > > > The assignment must be after the asserts: If the arguments are incorrect, > the assignment can crash the program. Fixed. > > Except for that, maybe we (including me, I know) should decide just what > the function should do before posting more code. Here are some points > that have been mentioned, half of them mine:-) > > 1) no padding, space-pad, '0'-pad, or make it an option: > a 'char padding' parameter where '\0' means no padding? No padding. A function should do one thing, and one thing well. A char padding parameter with e.g. the value '1' will also create 'interesting' output. > > 2) what to do if the buffer is not large enough: > Silently truncate, or generate a truncated string but return failure? > If the latter, should it return NULL or should we change the return > type so it returns the length of the string or -1 at truncation? (I > think it's ugly to return NULL at failure but still have a meaningful > output, but maybe that's just me?) We can add an assert for the debug version, but let the release version invoke UB. That's the error handling we have agreed upon. > > 3) malloc a buffer to be returned if the input ptr == NULL? > If so, must return ptr and not length in point (2) above. > Could let size==0 mean allocate whatever space is necessary. Do we need more Swiss Army Knife functions? [snip] > > 5) BTW, I'd like (2 <= base && base < 64): characters '0-9A-Za-z_=' > or something. That's because I expect I'd usually use *printf to > print normal numbers, but could use clc_ultostr with a large base > when I want to generate textual IDs. Base 64 is nice for that, which > is why I added "_" and "=" (two characters that hopefully have no > special meaning in filesystems and shell commands). How will you (or other users of libclc) convert it back to unsigned long? Just my 0.02 NOK... -- boa Please join the libclc-developers list at http://lists.sourceforge.net/lists/listinfo/libclc-developers |