In perl.perl6.internals, you wrote:
>Brent Dax <[EMAIL PROTECTED]> writes:
>
>> What about little inline things?
>
>> AUTO_OP sleep(i|ic) {
>> #ifdef WIN32
>> Sleep($1*1000);
>> #else
>> sleep($1);
>> #endif
>> }
>
>This reminds me. gcc is slowly switching over to writing code like that
>as:
>
> if (WIN32) {
> Sleep($1*1000);
> } else {
> sleep($1);
> }
>
>or the equivalent thereof instead of using #ifdef. If you make sure that
>the values are defined to be 0 or 1 rather than just defined or not
>defined, it's possible to write code like that instead.
If I recall correctly, Plan9's C compiler doesn't do #ifdef at all!
The perl5 source (#ifdef forest) was munged into the second form.
>It may not be possible to use this in cases where the not-taken branch may
>refer to functions that won't be prototyped on all platforms, depending on
>the compiler, but there are at least some places where this technique can
>be used, and it's worth watching out for.
Yes, a number of the #ifdef branches in perl5's pp_sys.c would
have this problem (odd structs present on some systems but not others,
for example). Also the VMS code with $ signs often gives other compilers
heartburn.
>(In the case above, I'd probably instead define a sleep function on WIN32
>that calls Sleep so that the platform differences are in a separate file,
>but there are other examples of things like this that are better suited to
>other techniques.)
Yes, that's what perl5 traditionally often tried to do. (See, for example,
the various defines in unixish.h: fwrite1, Stat, Fstat, Fflush, Mkdir).
Of course perl5 itself hasn't even always followed that plan . . . .
--
Andy Dougherty [EMAIL PROTECTED]
Dept. of Physics
Lafayette College, Easton PA 18042