[DRMAA-WG] C binding -- string lengths
rogerb at cadence.com
Thu Oct 23 12:49:52 CDT 2008
> it appeared to me that the size/length of buffer
> in C binding is still a bit messy...
I would agree that the phrase "size/length of buffer"
I would hope the document would either indicate the
size of the buffer, or the length of the string which
the buffer can accomodate.
> So if error_diag_len is supposed to mean size of the
> string buffer why sizeof(buf) is not used?
> Shouldn't it be called error_diag_size to be less confusing?
Yes, *IF* the intent was to accept the buffer size, then
the variable error_diag_size would be a better choice.
Since that's not the intent, it wasn't chosen.
> I know it's a little detail but I like things being consistent :)
Tricky to decide where to be consistent.
This business about needing an extra byte to terminate a string
is not particularly consistent between languages, and the
C-lang DRMAA binding is most certainly leveraged by other
From: "Piotr Domagalski" <piotr.domagalski at man.poznan.pl>
Sender: drmaa-wg-bounces at ogf.org
To: "DRMAA Working Group" <drmaa-wg at gridforum.org>
Subject: [DRMAA-WG] C binding -- string lengths
Date: Thu, 23 Oct 2008 17:29:28 +0200
As I've been lately looking at some example DRMAA code, e.g. the one
in the testsuite, it appeared to me that the size/length of buffer
in C binding is still a bit messy...
Almost all the example codes look like this:
drmaa_init(NULL, buf, sizeof(buf) - 1);
The third parameter is called err_diag_len. From DRMAA C Binding:
error_diagnosis A buffer into which error diagnosis information will
error_diag_len The size in characters of the error diagnosis string buffer.
So if error_diag_len is supposed to mean size of the string buffer why
sizeof(buf) is not used? Shouldn't it be called error_diag_size to be
I remember Hrabri saying that sizeof(buf) - 1 is to be used because
that is what programmers are used to. And I cannot agree with that.
This is what they use e.g. with strncpy() and it causes a *lot* of
confusion and errors (just man strncpy). Take a look at snprintf or
strftime which are supposed to get sizeof(buf), or strlcat/strlcpy
(not available in glibc) and it makes life a lot simpler -- you just
supply the total size of the buffer and don't worry about the output
being nul-terminated or not (it always is, even when the string is
I know it's a little detail but I like things being consistent :)
drmaa-wg mailing list
drmaa-wg at ogf.org
More information about the drmaa-wg