Search code examples
cidentifier

How to deal with intrusive identifiers from term.h?


Testing some code including term.h, I've seen some strange errors using usual identifiers such as tab or columns. It comes from the fact that this header defines a lot of macros. Here are some examples:

/* from term.h */

#define columns                        CUR Numbers[0]
#define lines                          CUR Numbers[2]
#define bell                           CUR Strings[1]
#define insert_line                    CUR Strings[53]
#define tab                            CUR Strings[134]

However, I didn't find any documentation about these macroconstants. It seems to be shortcuts to access to some members of a TERMINAL data structure. Of course, a solution is to #undef every identifier used in the source code. But it is very restrictive.

So my question is: why do not prefix the identifiers of term.h?
They are often used as local variables in real source code, so it leads to incomprehensible errors.


Solution

  • There are two ways to deal with the identifier clash:

    1. Change the identifiers in term.h
    2. Change the identifiers in your code

    The first is a no-no for reasons I hopefully need not explain. term.h was there long before your code ever formed as a thought in your brain. Thus it is entirely your fault^Wproblem^Wresponsibility to have created clashing identifiers. :-)

    Maybe there's another option:

    • Don't use/include term.h in the first place.