cpp hacking: bump FOO by 1

Hal Murray hmurray at megapathdsl.net
Sun Aug 30 17:12:03 UTC 2020


Is there any way to do something like
#define FOO $FOO+1

I want to keep track of the number of times a macro has been called.  That 
seems like something that would happen often enough that there would be a 
standard recipe but I haven't seen it.  (Or didn't recognize it.)

----------

The context is the code in ntp_control that is responding to ntpq requests to 
read a variable.  It needs to translate a string (name of variable to read) to 
a subroutine to print that variable.  Current code looks like:

#define CS_REFID                6
        { CS_REFID,             RO|DEF, "refid" },
#define CS_REFTIME              7
        { CS_REFTIME,           RO|DEF, "reftime" },
#define CS_POLL                 8
        { CS_POLL,              RO|DEF, "tc" },
#define CS_PEERID               9
        { CS_PEERID,            RO|DEF, "peer" },

That sets up the table to search.  The table is big (~100 slots) so it's a 
real pain to insert a new slot.

Later on, there is a giant select that uses those CS_xxx tags:

        case CS_ROOTDELAY:
                ctl_putdbl(sys_var[CS_ROOTDELAY].text,
                           sys_vars.sys_rootdelay * MS_PER_S);
                break;

        case CS_ROOTDISPERSION:
                ctl_putdbl(sys_var[CS_ROOTDISPERSION].text,
                           sys_vars.sys_rootdisp * MS_PER_S);
                break;

---------

One approach would be to have an external program do the equivalent of the cpp 
processing that we would like to do.  That would take some waf hacking, but 
shouldn't be a big deal.



-- 
These are my opinions.  I hate spam.





More information about the devel mailing list