[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
weak extern behaves erratically
From: |
Joe Korty |
Subject: |
weak extern behaves erratically |
Date: |
Fri, 5 Dec 2003 10:50:38 -0500 |
User-agent: |
Mutt/1.4i |
Hello,
weak externs are too eager to be defined ==NULL when in fact there is
a definition in a library they could be attached to. They seem only to
be willing to attach to definitions that have already been pulled in by
some other means. The attached script demonstrates the problem.
The most useful definition of weak extern is one that works exactly like
a non-weak extern except that, instead of generating a link edit failure
if the definition cannot be found, to define it NULL. I don't know if
that is the definition you are using, but if not I would hope you would
consider changing it to this.
Regards,
Joe
------------------------------------- script
cat <<EOF >wlib.c
void dummyfunc(void) {}
EOF
cc -O -c wlib.c
ar r wlib.a wlib.o
cat <<EOF >weak.c
extern int printf(const char *, ...);
extern void dummyfunc(void);
#ifdef WEAK
#pragma weak dummyfunc
#endif
int main(void)
{
printf("%p &%s\n", &dummyfunc, "dummyfunc");
return 0;
}
EOF
cc -DWEAK weak.c wlib.a && a.out
cc -DWEAK weak.c wlib.o && a.out
cc weak.c wlib.a && a.out
cc weak.c wlib.o && a.out
------------------------------------- script output
(nil) &dummyfunc
0x804835c &dummyfunc
0x804835c &dummyfunc
0x804835c &dummyfunc
- weak extern behaves erratically,
Joe Korty <=