Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!smurf!ipkama!freesid!mamnix!tjack!fiction!Daniel_Roedding From: Daniel_Roedding@fiction.ms.sub.org Newsgroups: comp.lang.c Subject: Two for one... Message-ID: <683194@fiction> Date: 29 Aug 90 23:12:16 GMT Lines: 67 X-Attributes: type 2, from 100, acclv 0, expires cchase@ee.cornell.edu (Craig M. Chase) writes: > 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. (...) > 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?) BTW: Do you really want a re-assignment when reaching this if-statement? I think it's more elegant to access such a hardware register by two pseudo-functions, e.g.: #define setreg(x,y) x=(y) #define getreg(x) (x) Then you could use: #define fancy_reg reg1 = reg2 ... and then: Your solution: > So, if I do > fancy_reg = 0xFFFF; > the preprocessor generates: > reg1 = reg2 = 0xFFFF; And the new one: setreg(fancy_reg,0xffff); -> reg1 = reg2 = (0xffff); When reading from the port: if (getreg(fancy_reg)==0xffff) -> if ((reg1 = reg2) == 0xffff) Probably it's more elegant -- but it's no good when you access the registers very often (or do you like to hundredfold write rendundant stuff like "getreg"? - anyway, it's the way how *I* would solve the problem). Daniel --- Daniel Roedding #include Geiststrasse 32 "This golden age of communication D-4400 Muenster Means everyone talks at the same time" (NMA) ++49 251 525306 daniel@fiction.ms.sub.org; ..!uunet!mcsun!unido!mcshh!veeble!fiction!daniel