From: B. Watson (atari_at_hardcoders.org)
Date: 2001-07-16 07:56:24
I'm new to the list, I didn't see any mention of this in the archives...
The following code won't compile with either cc65-2.6.1 or the 7/15 snapshot:
#include <stdio.h>
int foo(void) {
char j=1;
return(j);
}
main() {
int (*func)(void) = foo; /* compiler chokes here */
printf("%d\n",func());
}
The compiler chokes at the marked line, with Error: Incompatible pointer types
(however, it compiles just fine with gcc, and doesn't produce warnings with
-Wall)
However, this code compiles just fine:
#include <stdio.h>
int real_foo(void) {
char j=1;
return(j);
}
int foo(void) {
return real_foo();
}
main() {
int (*func)(void) = real_foo;
printf("%d\n",func());
}
...and runs properly (prints `1')... More generally, I don't seem to be able
to assign a pointer to a function, if that function declares any local storage
at all.
Of course, the problem can be worked around by declaring `wrapper' functions
like the second example above, but this seems like a bug to me (and no, I'm
not enough of a C coder to figure it out in a reasonable amount of time,
or I'd submit a patch...)
In case it matters, I've tried it on both a Linux (Slackware 7.0) and a
Solaris 2.6 sparc machine, with identical results (side note: you can add
Solaris to the list of platforms cc65 runs on, on the web site... So
far, identical behavior on Linux and Solaris)
B. Watson
---
If a trainstation is the place where trains stop, what is a workstation?
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:40 CET