Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!bloom-beacon!mintaka!think!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!jarthur!aqdata!sullivan From: sullivan@aqdata.uucp (Michael T. Sullivan) Newsgroups: comp.lang.c Subject: Multi-statement macros (again) Message-ID: <1990Feb8.235051.21779@aqdata.uucp> Date: 8 Feb 90 23:50:51 GMT Organization: aQdata, Inc. Western Region -- San Dimas, CA Lines: 30 One of the packages we use has some macros for returning values from a function. You call these macros when you want to return instead of calling return. An example is: #define new_return(n) s1; s2; return (something) This just wouldn't do so I put braces around the statements. Recent discussion here led me to change this macro to: #define BEGIN_BLOCK do { #define END_BLOCK } while (0) #define new_return(n) BEGIN_BLOCK s1; s2; return (something); END_BLOCK Problem with this particular macro is that because it has a return in it, we would get a "statement not reached" warning from the compiler. I then changed BEGIN_ and END_BLOCK to: #define BEGIN_BLOCK do { if (1) { #define END_BLOCK } } while (0) This seems to make everything happy. My question is, will this make other machines happy? We are using a 3B2/400 SVR3 and it didn't even complain when just braces were used (resulting in "};"). Does this shut everything up on YOUR machine? P.S. That BEGIN_BLOCK/END_BLOCK stuff really DOES come in handy. -- Michael Sullivan uunet!jarthur!aqdata!sullivan aQdata, Inc. sullivan@aqdata.uucp San Dimas, CA +1 714 599 9992