Re: Design question dealing with char* function



On 28 Jul 2005 08:50:05 -0700, fernandez.dan@xxxxxxxxx wrote in
comp.lang.c:

> My question is about if I should return char* or have a char* as an
> argument. My basic premise for this function is to return a char*
> buffer and the size of the buffer to the caller. I know that each of
> the following works but Stylistic which would be the better approach.
>
> Here are my two examples:
>
> char* GetBuffer(long* size);
>
> or
>
>
> void GetBuffer(char* buff, long* size);
>
>
> Thanks
>
>
> Danny

Don't use long for sizes. That's not what it is for, and it is quite
possible that on the 64-bit systems that are going to become common
soon objects can be larger than an unsigned long, let alone a signed
one.

Use size_t for the size of things, that is what it is for. There will
never be an implementation where an object will exist with a size too
large to fit into a size_t.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
.



Relevant Pages