Dave Thomas <Dave / PragmaticProgrammer.com> wrote: > "Aleksei Guzev" <aleksei.guzev / bigfoot.com> writes: > > > Just now I met a funny problem with NUM2LONG macro. > > > > I've written a line like the following > > > > return NUM2LONG( fn( x ) ); > > > > Function fn has vivid side effect and NUM2LONG calls it twice ( see > > its definition ) :) Do not do like above! > > Patient: Doctor, it hurts when I type this. > > Doctor: Then don't type that. > > > Just call rb_num2long(fn(x)) directly. The definition should be trivially fixed, nonetheless... the rules I've learned for the implementation of macros have been: * if they're meant to be a block of code not returning a value, they should be in "do { code } while (0)" * parameters must be parenthesized in the implementation to allow for arbitrary expressions without operation order interference * all parameters should be evaluated only once. Generally, these are all easy to do and result in much more robust macros that don't break in ways people don't expect. -- Brian Fundakowski Feldman \ FreeBSD: The Power to Serve! / green / FreeBSD.org `------------------------------'