Two variables for the price of one
Craig M. Chase
cchase at ee.cornell.edu
Mon Aug 27 00:44:03 AEST 1990
Hi, I'm working on a a project involving the direct manipulation of
some hardware registers in some custom circuitry. For reasons that
I won't go into here, we've got a bunch of registers that work as
pairs. What I mean is that (unless something goes drastically
wrong) these registers will always have the save value. When I
write to one, I really want to write to both.
So... my question is, does anybody know any neat tricks in the
C preprocessor to define a single name that will work with both
registers. As a seed suggestion, let me tell you what I tried:
#define fancy_reg reg1 = reg2
So, if I do
fancy_reg = 0xFFFF;
the preprocessor generates:
reg1 = reg2 = 0xFFFF;
which is great.
Problem is, if I try:
if (fancy_reg == 0xFFFF)
I get:
if (reg1 = reg2 == 0xFFFF)
and that doesn't do the right thing (== binds tighter than =, right?)
The only solution to this that I've seen is to always use parenthesis
around fancy_reg when I want to read the register pair, and avoid
the parenthesis when I want to write them. This solution is hardly
preferable to manipulating the two registers independently.
Any suggestions?
Craig Chase
--
----------------------------------------------------------------------
Craig Chase | Cornell University
cchase at ee.cornell.edu | Department of Electrical Engineering
----------------------------------------------------------------------
More information about the Comp.lang.c
mailing list