How to deal with intrusive identifiers from term.h?

Testing some code, including term.h , I saw some strange bugs using regular identifiers like tab or columns . This is because this header defines many 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 did not find any documentation about these macro constants. These seem to be shortcuts to access some members of the TERMINAL data structure. Of course, the solution is to #undef each identifier used in the source code. But it is very restrictive.

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

+4
source share
2 answers

There are two ways to deal with an identity conflict:

  • Change the identifiers in term.h
  • Change the identifiers in the code

The first is no-no for reasons that I hope do not need to be explained. term.h was long before your code ever formed like a thought in your brain. So this is completely your mistake. Wresblems Wresponsibility created conflicting identifiers. :-)

Perhaps there is another option:

  • Do not use / include term.h in the first place.
+5
source

One option, assuming you MUST use term.h, is to isolate the inclusion of this file in a specific module so that your common code does not collide. But, as Jens says, your task is "not to have personal clashes." Public header files belonging to the system should not be changed just because you use the same names as those specified.

+1
source

All Articles