From: "daz (c)" Date: 2007-12-14T20:29:50+09:00 Subject: Re: IRHG - PUSH_FRAME? Charles Thornton wrote: > The following define statement is driving me crazy > I have never seen a #define used this way! > > Can someone explain what is going on here? > > Does this somehow create a new frame without > allocation, and add it to a ruby_frame linked list? > > #define PUSH_FRAME() do { \ > struct FRAME _frame; \ > _frame.prev = ruby_frame; \ > _frame.tmp = 0; \ > _frame.node = ruby_current_node; \ > _frame.iter = ruby_iter->iter; \ > _frame.argc = 0; \ > _frame.flags = 0; \ > _frame.uniq = frame_unique++; \ > ruby_frame = &_frame > > #define POP_FRAME() \ > ruby_current_node = _frame.node; \ > ruby_frame = _frame.prev; \ > } while (0) > > C90 compilers won't allow a declaration (struct) amid code, so it's wrapped in a run-once-only block "do {...} while(0)". The declaration is at the top of the new block so a compiler error is avoided. For some reason just "{...}" doesn't work in all cases, so it was changed in rev 2401: http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/eval.c?view=diff&r1=2400&r2=2401 Subsequent use of POP_FRAME() closes the block. They are two distinct macro definitions although POP_FRAME() might look embedded to the human eye. ;) (Absence of backslash marks the end of a macro.) daz