| re: macro magic: include a while loop and return result?
On Thu, 27 May 2004, Sten Westerback wrote:
[color=blue]
> Well, as busy looping is not good way of programming
> and your question also seems more targeted at comp.lang.c
> or comp.lang.c++ .. ask there.. :)
> But it would seem you need to stick with a function... or two.[/color]
Busy looping IN GENERAL is not usually the best way of programming, and
here it is the only way to accomplish what I need to accomplish:
while (foo() == BUSY) Sleep(100);
The function foo() will rarely be busy, so most often it will succeed the
first time. Moreoever, there is no way to be signalled when foo() is not
busy. Thus, the loop is not only the only way to do this, it is an
appropriate way to do it.
[color=blue]
> and your question also seems more targeted at comp.lang.c
> or comp.lang.c++ .. ask there.. :)[/color]
It is admittedly not related to Win32, but it is related to Microsoft
Visual C++ 6.0 (MSVC), because that compiler defines various extensions to
the C and C++ languages and has various quirks of its own. I searched
Google Groups for MSVC and the c.os.m-w.p.win32 newsgroup turned up the
most hits.
[color=blue]
> But it would seem you need to stick with a function... or two.[/color]
No, a function won't work, because C and C++ evaluate the arguments to a
function before calling the function.
int wrap(int X) {
int retval;
while ((retval = X) == BUSY) { Sleep(100); }
return retval;
}
It should be obvious why that would work as a macro but not as a function.
If you're tricky, you'll suggest passing a function pointer as the
argument X, but that's not ideal, because the functions X that are wrapped
take all sorts of different types and numbers of arguments.
Tobin |