On Feb 7, 2011, at 16:19, Dr. H. Nikolaus Schaller wrote: > > > Just another idea I would like to propose for discussion > is to follow the "bracket-style" of NS_DURING NS_HANDLER & NS_END_HANDLER > macros (http://www.cocoadev.com/index.pl?ExceptionHandling) > > I.e. something like: > > #define FOREACH(TYPE, VAR, COLLECTION) { NSEnumerator *_e=[(COLLECTION) > objectEnumerator]; TYPE VAR; while((VAR = [_e nextObject])) { > #define FOREACH_END } } > > The benefit would be that it appears to be a little more safe against errors > than > > if(i == 0) > foreach(...) > if(j == 0) > ... > else > ...
The macros I posted have the same rules WRT braces as a normal for loop. If you're going to use FOREACH_END, you might as well use FOR_END and IF_END macros, or - more practically - require every if body to use braces. > Finally, I think it should also be possible to rename the internal > variable _e by macro name generation > so that nested enumerations have private enumerator variables. > > Something like ... NSEnumerator *_e##VAR; This isn't necessary; nested enumerations each have their own scope. -- Jens Ayton _______________________________________________ Discuss-gnustep mailing list [email protected] http://lists.gnu.org/mailman/listinfo/discuss-gnustep
