SPUG: can't leave well enough alone Re: PERL technical interview

Fred Morris m3047 at inwa.net
Mon Jan 23 18:28:53 PST 2006


Take two, the function is named EXIT_SUCCESS.. OK, you can shoot me now.
This code scares me; I worry about what might be assuming something
entirely reasonable about EXIT_SUCCESS being defined as a macro... But it
runs on the linux box sitting here on the desk. I'm done, I promise!

#!/usr/bin/perl -w

use Inline C;

use strict;

print 'EXIT_SUCCESS is ';

if (defined( my $code = &EXIT_SUCCESS)) {
    print "defined as $code\n";
    exit($code);
}
else {
    print "undefined\n";
}

__END__

__C__

#include <stdlib.h>

#ifdef EXIT_SUCCESS
static int saved_code_defined = 1;
static int saved_code = EXIT_SUCCESS;
#undef EXIT_SUCCESS
#else
static int saved_code_defined = 0;
static int saved_code = 0;
#endif

void EXIT_SUCCESS() {

    Inline_Stack_Vars;
    Inline_Stack_Reset;

    if (saved_code_defined) {
        Inline_Stack_Push(sv_2mortal(newSViv(saved_code)));
    }
    else {
        Inline_Stack_Push(sv_2mortal(newSV(0)));
    }

    Inline_Stack_Done;
}

--

Fred Morris




More information about the spug-list mailing list