[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sig2str and str2sig use in C++

From: Daniel J Sebald
Subject: Re: sig2str and str2sig use in C++
Date: Tue, 04 Jun 2013 12:35:00 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16

On 06/04/2013 02:47 AM, Thien-Thi Nguyen wrote:
() Paul Eggert<address@hidden>
() Mon, 03 Jun 2013 15:28:24 -0700

    extern char const allsigstr[];

    This would consist of a concatenation of null-terminated strings,
    one per name, terminated by an empty string.

    [compile time wins]

I seem to recall a paper several years back that argued against this
approach based on ldso issues.  Drat, can't dredge the details...

I tried searching the Internet for such issues, but couldn't find any. What do you recall as being the loader problem? The "extern" part? Or use of a null string for termination?

I'm just thinking, Paul, if the null termination/index pointer idea were used throughout the string array, one could continue to use the

int sig2str (int, char *);

function in a backward compatible way. (I had ruled that out with the run-time dynamic creation of such a thing, but with the indexing, there should be no re-entry problems.) The fundamental string array would look like this, as an example:


If the numname[] array then had a pointer to the first entry in the above string array it would produce the equivalent of the existing routine with the extension to continue reading null-terminated strings until the empty string. However, this doesn't seem like an easy thing to sort through at compile-time unless the macro were written in such a way that it included duplicates. For example (assuming there would never be more than two or three duplicates) the following illustrates conceptually (but perhaps syntactically it's dubious):

#define NUMNAME(name) { SIG##name, #name }
#define NUMNAME2(name1, name2) { ??? some kind of ##ifdef logic }
#define NUMNAME3(name1, name2, name3) { ??? some kind of ##ifdef logic }

/* Signal names and numbers.  Put the preferred name first.  */
static struct numname { int num; char const name[8]; } numname_table[] =
    { 0, "EXIT" }


reply via email to

[Prev in Thread] Current Thread [Next in Thread]