SPUG: PERL technical interview

Fred Morris m3047 at inwa.net
Mon Jan 23 16:21:52 PST 2006


Don't ask me to do this in an interview, but I couldn't resist.

#!/usr/bin/perl -w

use Inline C;

use strict;

print 'EXIT_SUCCESS is ';

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

__END__

__C__

#include <stdlib.h>

void SHELL_SUCCESS() {

    Inline_Stack_Vars;
    Inline_Stack_Reset;

#ifdef EXIT_SUCCESS
    Inline_Stack_Push(sv_2mortal(newSViv(EXIT_SUCCESS)));
#else
    Inline_Stack_Push(sv_2mortal(newSV(0)));
#endif

    Inline_Stack_Done;
}

--

Fred Morris

--

At 9:59 AM 1/23/06, Yitzchak Scott-Thoennes wrote:
>[...]
>I've worked on a platform where the above is buggy.  Canonically bug-free
>would be more like:
>
>#include <stdlib.h>
>#ifndef EXIT_SUCCESS
>#define EXIT_SUCCESS 1
>#endif
>
>int main(int argc, char *argv[], char *envp[]) {
>   return EXIT_SUCCESS;
>}




More information about the spug-list mailing list