Re: style question,itoa
- From: moi <root@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 25 Jan 2008 00:20:49 +0100
On Thu, 24 Jan 2008 21:02:12 +0100, Syren Baran wrote:
Frank Cusack schrieb:
I learned b) the hard way a long time ago. Thats why i document theGood to know you know that i will have an easier time reading my code
when using functions i wrote that behave as i wanted to. I didnt know
that yet.
an all too common error to assume
a) no one else will ever read your code. b) you will remember how any
function behaves.
functions. That way they will not only "behave as i wanted to", but also
as i document them.
Yupp, but anyway that file will contain the notice "All functions below
admittedly in this case it's rather trivial.
that return a char* require the caller to free the char*."
-frank
For this kind of formatting-functions the snprintf() kind of interface is
perfect:
*) it cannot overrun the buffer (once coded correctly)
*) if it would: it returns a negative value.
*) if it succeeds, it returns the amount written,
such that buffer[return_value] == '\0'; which makes is easy to fill the
buffer in multiple calls, and without excess copying.
Utility functions, returning malloc()ed chunks need return value testing
by the caller. The snprintf() method does so also, but (on failure) it
does *not* need to free() the preceding chunks, which means it is shorten
and less error prone.
YMMV,
AvK
.
- Follow-Ups:
- Re: style question,itoa
- From: Syren Baran
- Re: style question,itoa
- From: Frank Cusack
- Re: style question,itoa
- From: Frank Cusack
- Re: style question,itoa
- References:
- style question,itoa
- From: Syren Baran
- Re: style question,itoa
- From: David Schwartz
- Re: style question,itoa
- From: Syren Baran
- Re: style question,itoa
- From: Robert Latest
- Re: style question,itoa
- From: Syren Baran
- Re: style question,itoa
- From: Frank Cusack
- Re: style question,itoa
- From: Syren Baran
- Re: style question,itoa
- From: Frank Cusack
- Re: style question,itoa
- From: Syren Baran
- style question,itoa
- Prev by Date: Re: SCTP reference implementation
- Next by Date: Re: style question,itoa
- Previous by thread: Re: style question,itoa
- Next by thread: Re: style question,itoa
- Index(es):
Relevant Pages
|