Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!batcomputer!rtaylor From: cchase@ee.cornell.edu (Craig M. Chase) Newsgroups: comp.lang.c Subject: Two variables for the price of one Keywords: C Preprocessor Message-ID: <1990Aug26.144403.17638@batcomputer.tn.cornell.edu> Date: 26 Aug 90 14:44:03 GMT Sender: rtaylor@batcomputer.tn.cornell.edu (Russ Taylor) Organization: Cornell Dept. of Electrical Engineering Lines: 42 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@ee.cornell.edu | Department of Electrical Engineering ----------------------------------------------------------------------