libctf: can I reuse Bruno's code from appendix B of Uli's DSO howto?
Bruno Haible
bruno@clisp.org
Tue Apr 14 16:11:02 GMT 2020
Hi Nick,
> Bruno wrote a nice little
> automated fix for this general problem: it's included in Uli's DSO howto
> at <https://www.akkadia.org/drepper/dsohowto.pdf>: rather than
> re-engineering it, I thought I'd add a buncha comments and reuse the
> code in libctf.
>
> But it's probably long enough and surely tricksy enough to be
> copyright-significant in the FSF's eyes
The code I originally sent to Ulrich, and which I hereby put in the public
domain:
#include <stddef.h>
#define MSGSTRFIELD(line) MSGSTRFIELD1(line)
#define MSGSTRFIELD1(line) str##line
static struct msgstr_t {
#define _S(s) char MSGSTRFIELD(__LINE__) [sizeof(s)];
#include "stringtab.h"
#undef _S
} msgstr = {
#define _S(s) s,
#include "stringtab.h"
#undef _S
};
static int msgidx[] = {
#define _S(s) offsetof(struct msgstr_t, MSGSTRFIELD(__LINE__)),
#include "stringtab.h"
#undef _S
};
const char *errstr (int nr) {
return (char*)&msgstr + msgidx[nr];
}
And stringtab.h contains:
_S("message for err1")
_S("message for err2")
_S("message for err3")
The changes Ulrich did were:
- Add a parameter 'n' to the _S macro, to avoid mismatches between index
and message.
- Turn msgstr_t into a union with an unnamed struct as first element,
to get rid of the cast (char*)&msgstr that may trigger a GCC warning.
Bruno
More information about the Binutils
mailing list