Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
I have an old macro that doesn't seem to work any more....
I have an old macro
#define CTRL(c) ('c' & 037)
that doesn't seem to work any more.
✍: Guest
The intended use of this macro is in code like
tchars.t_eofc = CTRL(D);
which is expected to expand to
tchars.t_eofc = ('D' & 037);
based on the assumption that the actual value of the parameter c will be substituted even inside the single quotes of a character constant. Preprocessing was never supposed to work this way; it was somewhat of an accident that a CTRL() macro like this ever worked.
ANSI C defines a new ``stringizing'' operator , but there is no corresponding ``charizing'' operator.
The best solution to the problem is probably to move the single quotes from the definition to the invocation, by rewriting the macro as
#define CTRL(c) ((c) & 037)
and invoking it as
CTRL('D')
(Doing so also makes the macro ``syntactic'';
It may also be possible to use the stringizing operator and some indirection:
#define CTRL(c) (*#c & 037)
or
#define CTRL(c) (#c[0] & 037)
but neither of these would work as well as the original, since they wouldn't be valid in case labels or as global variable initializers. (Global variable initializers and case labels require various flavors of constant expressions, and string literals and indirection aren't allowed.)
2016-01-25, 1473👍, 0💬
Popular Posts:
What is AL.EXE and RESGEN.EXE? In the previous question you have seen how we can use resource files ...
How does one iterate through items and records in a specified block? One can use NEXT_FIELD to itera...
What is the purpose of the wait(), notify(), and notifyAll() methods? The wait(),notify(), and notif...
How can we connect to Microsoft Access , Foxpro , Oracle etc ? Microsoft provides System.Data.OleDb ...
What Is Paint Shop Pro? - PSP Tutorials - Fading Images to Background Colors with PSP Paint Shop Pro...