Re: rvalue

From: Keith Thompson (kst-u_at_mib.org)
Date: 04/09/04


Date: Fri, 09 Apr 2004 05:55:54 GMT

Tobias Oed <tobias@physics.odu.edu> writes:
> Hi all, It's been a while!
> I'm working on a very buggy piece of code that uses a lot of macros.
> A bunch of them look like
> #define POSITION(mw,row) (mw.positions[row])
> In order to debug the thing I'd like to modify these macors so they
> can only be used as rvalues and not as lvalues. If they are used as
> lvalues I want my compililation to fail. Unfortunately I can't
> remember a nice way to do that.

Assuming the result is numeric, I think this will work.

#define POSITION(mw,row) (+mw.positions[row])

I usually prefer to enclose all reference to macro arguments in
parentheses to avoid operator precedence problems, but I don't *think*
it's necessary in this case (though it won't hurt to do it anyway).

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"


Relevant Pages

  • Re: rvalue
    ... > I'm working on a very buggy piece of code that uses a lot of macros. ... > used as rvalues and not as lvalues. ... Works for numeric and for non-numeric types. ...
    (comp.lang.c)
  • rvalue
    ... I'm working on a very buggy piece of code that uses a lot of macros. ... A bunch of them look like ... If they are used as lvalues I want my ...
    (comp.lang.c)
  • Re: rvalue
    ... > I'm working on a very buggy piece of code that uses a lot of macros. ... > A bunch of them look like ... > used as rvalues and not as lvalues. ... Maybe remove the macros if you can. ...
    (comp.lang.c)
  • Re: [PATCH] Documentation: Explain a second alternative for multi-line macros.
    ... inline functions are preferable to macros resembling functions. ... -Macros with multiple statements should be enclosed in a do - while block: ... If there is no return value from the macro, you should enclose ...
    (Linux-Kernel)
  • Re: Macros: returning multiple lists
    ... The standard mechanism to have multiple forms returned from macros is to ... enclose them in a PROGN. ...
    (comp.lang.lisp)