----- Original Message ----- From: "Ken Williams" <[EMAIL PROTECTED]> To: "Sisyphus" <[EMAIL PROTECTED]> Cc: "inline" <inline@perl.org> Sent: Monday, April 10, 2006 2:55 AM Subject: Re: #ifdef and Inline::C
> > On Apr 7, 2006, at 9:24 PM, Sisyphus wrote: > > > Hi, > > > > The following code builds and runs fine on linux (perl 5.8.8), but > > won't > > compile on Win32 (perl 5.8.8): > > > > use warnings; > > use Inline C => Config => > > BUILD_NOISY => 1; > > > > use Inline C => <<'EOC'; > > > > #ifdef RUBBISH > > > > void greet1() { > > printf("Hello 1\n"); > > > > //#else > > > > //void greet1(){} > > > > #endif > > > > void greet2() { > > printf("Hello 2\n"); > > } > > > > EOC > > > > greet2(); > > > > __END__ > > > > 'RUBBISH' is not defined on either box. > > > > Here's the error I get on Win32: > > > > try_pl_7b60.o(.text+0x7e):try_pl_7b60.c: undefined reference to > > `greet1' > > collect2: ld returned 1 exit status > > dmake: Error code 129, while making > > 'blib\arch\auto\try_pl_7b60\try_pl_7b60.dll > > I don't get it, where is there any reference to greet1() when RUBBISH > is not defined? > Yes - I didn't explain it very well. When RUBBISH is not defined greet1() will never be called (note that the script never calls greet1), so there's no need for any reference to greet1(). Linux seems quite happy with that, but Windows doesn't - an unexpected situation. I've decided to do it along these lines: #ifdef PERL58 SV * foo(SV * arg) { // do its stuff and return an SV } #else SV * foo(SV * arg) { croak("This function should not have been called"); } #endif It's probably the correct thing to do - at least it looks like the *thorough* thing to do. It still seems a little odd to me because the module will *never* call foo() if PERL58 is not defined. But I guess it would always be possible to call foo() by it's fully-qualified name, and if that was ever done when PERL58 was not defined then it would be better to see a croak() message rather than some sort of segfault. The other thing that strikes me as odd about the '#else' version of foo() is that it is never going to return anything, though the prototype specifies that it will return an SV*. None of the compilers that I have used seem bothered by that, so it's not going to bother me too much, either :-) Thanks Ken. Cheers, Rob