Oh nooo! (gotos)

Roland Schemers schemers at egrunix.UUCP
Fri Sep 8 01:06:10 AEST 1989


>   While we are on the subject of loops, how do people feel about the
>   practice of using #define to "extend" the language?  For example:
>
>   #define loop     for (;;)
>   #define exitloop break
>
>   loop {
>	foo();
>	if (bar()) exitloop;
>   }
>

I thought about using the same type of #defines, but what happens when
you have the following:

   loop {
	....
	while (x<h) {		// or a for(;;) loop
 	     ...
             ...
	     exitloop;
	}
	....
    }

Wont the exitloop cause the while to break? This construct looks nice,
as long as you remember that you cant have any other loops (while, for, etc)
inside of your loop construct. How about:

#define begin_loop(name) for(;;)
#define end_loop(name)   name:;
#define exit_loop(name)  goto name;

	begin_loop(read_line) {
	...
	if (whatever) exit_loop(read_line);
	...
	} end_loop(read_line)

I haven't tried this, so I don't know if it is syntatically correct.

roland

ps. personally I think redefining the langauge causes more problems then it
is worth. For personel use its fine, but once other programmers have to
start modifing your code, it only leads to problems.

-- 
Roland J. Schemers III                  'Real programmers don't write specs.
Systems Programmer                      Users should be grateful for whatever
Oakland University                      they get. They are lucky to get any
schemers at unix.secs.oakland.edu		programs at all.'



More information about the Comp.lang.c mailing list