Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!sun-barr!newstop!sun!sun.com From: david@sun.com (``Bob'' is the gun and YOU are the bullet...) Newsgroups: comp.lang.c Subject: Re: Using macros as statements (Re: Typeof operator in C) Message-ID: <130338@sun.Eng.Sun.COM> Date: 16 Jan 90 22:52:22 GMT References: <16678@megaron.cs.arizona.edu> <7106@tank.uchicago.edu> <-K016ODxds13@ficc.uu.net> <721@eedsp.eedsp.gatech.edu> <19840@watdragon.waterloo.edu> Sender: david@sun.Eng.Sun.COM Lines: 22 In article <19840@watdragon.waterloo.edu> smking@lion.waterloo.edu (Scott M. King) writes: >To make a macro behave exactly as a statement, replace the { and } in >the macro definition with START_MACRO and END_MACRO: >#define START_MACRO do { >#define END_MACRO } while ( 0 ) Unfortunately this is not lint-compatible ("constant in conditional context"). I use a slight variation: #ifdef lint int _ZERO_; #else #define _ZERO_ 0 #endif #define _STMT(s) do { s } while (_ZERO_) #define FOO(bar) _STMT(if (bar) frob();) -- David DiGiacomo, Sun Microsystems, Mt. View, CA sun!david david@eng.sun.com