* library routine wrappers and serious overkill
@ 2005-06-05 21:34 Robert P. J. Day
2005-06-06 1:13 ` Glynn Clements
0 siblings, 1 reply; 3+ messages in thread
From: Robert P. J. Day @ 2005-06-05 21:34 UTC (permalink / raw)
To: C programming list
yet another curious feature of this code base that i'm now looking
after. apparently, the original author was a big believer in
robustness, given that he wrapped numerous simple library routines
with assertions and dbug.h macros, as in:
===========================
void
my_str_copy(char *const dest_p,
size_t dest_size,
char const *const source_p,
size_t const source_size)
{
DBUG_ENTER(__FUNCTION__);
my_CONDITION(dest_p || dest_size == 0);
my_CONDITION(source_p || source_size == 0);
if (dest_p && 0 < dest_size) {
if (source_p == 0) {
dest_size = 1;
} else if (source_size < dest_size) {
dest_size = source_size + 1;
}
strncpy(dest_p, source_p, --dest_size);
dest_p[dest_size] = 0;
}
DBUG_VOID_RETURN;
}
==============================
now, i'm as big a fan as the next guy of good debugging (the
my_CONDITION macro is a local implementation of assert() with hooks to
a logging library -- yeesh) but, seriously, there has to be a limit to
just how much debugging you're going to apply to each and every
string-related library routine. it does get kind of absurd after a
while:
===============================
char
my_str_ch2upper(char const ch)
{
DBUG_ENTER(__FUNCTION__);
if (isascii(ch) && islower(ch)) {
DBUG_RETURN(toupper(ch));
}
DBUG_RETURN(ch);
}
===============================
is this what you'd call best practice? am i just being too
critical? is there a more established combination of
debugging/assertions/logging that people use? based on a previous
posting, i'm looking hard at "log4c" for the logging part.
rday
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: library routine wrappers and serious overkill
2005-06-05 21:34 library routine wrappers and serious overkill Robert P. J. Day
@ 2005-06-06 1:13 ` Glynn Clements
2005-06-06 21:29 ` Robert P. J. Day
0 siblings, 1 reply; 3+ messages in thread
From: Glynn Clements @ 2005-06-06 1:13 UTC (permalink / raw)
To: Robert P. J. Day; +Cc: C programming list
Robert P. J. Day wrote:
> now, i'm as big a fan as the next guy of good debugging (the
> my_CONDITION macro is a local implementation of assert() with hooks to
> a logging library -- yeesh) but, seriously, there has to be a limit to
> just how much debugging you're going to apply to each and every
> string-related library routine. it does get kind of absurd after a
> while:
>
> ===============================
>
> char
> my_str_ch2upper(char const ch)
> {
> DBUG_ENTER(__FUNCTION__);
>
> if (isascii(ch) && islower(ch)) {
> DBUG_RETURN(toupper(ch));
> }
> DBUG_RETURN(ch);
> }
>
>
> ===============================
>
> is this what you'd call best practice?
It may be that the code was written for a platform which lacked a
working debugger, so the program had to be able to generate its own
stack traces etc.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: library routine wrappers and serious overkill
2005-06-06 1:13 ` Glynn Clements
@ 2005-06-06 21:29 ` Robert P. J. Day
0 siblings, 0 replies; 3+ messages in thread
From: Robert P. J. Day @ 2005-06-06 21:29 UTC (permalink / raw)
To: Glynn Clements; +Cc: C programming list
On Mon, 6 Jun 2005, Glynn Clements wrote:
> Robert P. J. Day wrote:
>
> > now, i'm as big a fan as the next guy of good debugging (the
> > my_CONDITION macro is a local implementation of assert() with hooks to
> > a logging library -- yeesh) but, seriously, there has to be a limit to
> > just how much debugging you're going to apply to each and every
> > string-related library routine. it does get kind of absurd after a
> > while:
> >
> > ===============================
> >
> > char
> > my_str_ch2upper(char const ch)
> > {
> > DBUG_ENTER(__FUNCTION__);
> >
> > if (isascii(ch) && islower(ch)) {
> > DBUG_RETURN(toupper(ch));
> > }
> > DBUG_RETURN(ch);
> > }
> >
> >
> > ===============================
> >
> > is this what you'd call best practice?
>
> It may be that the code was written for a platform which lacked a
> working debugger, so the program had to be able to generate its own
> stack traces etc.
in fact, that's exactly the case -- this code is for an embedded
system for which debugging capabilities are limited. my point was
more that it seemed like overkill to add "dbug"-type wrapping around a
routine that did nothing more than convert a character to upper case.
and, on top of that, the input validation above is redundant -- the
definition of "toupper" is that it already checks whether the input
character is lower case before performing the conversion.
in any case, i have no beef with debugging code. but i think there
are times when one gets a bit carried away.
rday
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-06-06 21:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-05 21:34 library routine wrappers and serious overkill Robert P. J. Day
2005-06-06 1:13 ` Glynn Clements
2005-06-06 21:29 ` Robert P. J. Day
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).