develooper Front page | perl.perl5.porters | Postings from September 2003

Re: Interesting - [drow@mvista.com: Re: A user's experiences with GCC-3. 4 snapshots]

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
September 18, 2003 14:59
Subject:
Re: Interesting - [drow@mvista.com: Re: A user's experiences with GCC-3. 4 snapshots]
Message ID:
20030918214018.2645.4@llama.ni-s.u-net.com
Mark Jason Dominus <mjd@plover.com> writes:
>> > int main() { extern void *setproctitle(); if(&setproctitle) return(0); else return(1); }
>> 
>> This is not a valid way to test the existence of a function, and GCC is
>> correct.  You are declaring that there is an external symbol named
>> setproctitle, and asking for its address.  The C standard guarantees
>> that the address of a function will never compare equal to NULL.
>> 
>> So Perl needs to be fixed.
>
>I thought the idea of this sort of test was that if there is no
>setproctitle, the attempt to link the 'try' program will fail; the
>'if' test isn't important, and the program, if it compiles and links,
>will always return 0.
>
>If I understand correctly, gcc-3.4 is smart enough to optimize out the
>reference to 'setproctitle', so the resulting .o file doesn't refer to
>'setproctitle', and the linker always succeeds.  If that's what's
>going on, then something like this should be enough to defeat the
>optimization and fix the problem:
>
>#include <stdio.h>
>int main() { extern void *setproctitle(); if(setproctitle == main) return(0); else return(1); }

gcc could decide that two functionwith different "signatures" could not 
be at same address. Best thing to do is stuff it in a variable:

extern void *setproctitle();
void *(*var)();
int main() { if (!var) var = setproctile; ... } 




Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About