Hi,
I'm not sure if I'm struggling with my limited knowledge of function pointer syntax or with Pelles C.
The code snippet below (don't ask what it does) compiles flawlessly with gcc, but not with Pelles C V13
(32 bit console mode).
With Pelles C I get the following errors
E:\Develop\M3\fp.c(12): error #2168: Operands of '=' have incompatible types: 'int (*)()' and 'void *'.
E:\Develop\M3\fp.c(15): error #2168: Operands of '=' have incompatible types: 'int (*)(int, ...)' and 'void *'.
E:\Develop\M3\fp.c(18): error #2168: Operands of '=' have incompatible types: 'int (*)(int, ...)' and 'void *'.
I tried many things, including typedefs, without success. But I can't make it work.
Many thanks for your help!!
// ------
#include <stdlib.h>
int pop(void) { return rand()&3; }
int tos=0x123456;
int (*pz)();
int (*pn)(int,...);
void runproc(void) { // RUNPROC ( .. fa n -- ret )
int p1, p2;
switch (pop()) {
case 0: pz=(void*)tos;
tos=pz();
break;
case 1: pn=(void*)pop(), p1=tos;
tos=pn(p1);
break;
case 2: pn=(void*)pop(), p2=pop(), p1=tos;
tos=pn(p1,p2);
break;
default: tos=-21; }
}
int main(void) {
runproc();
return tos;
}
// ------
OK, the quick & dirty version (with minimum changes):
#include <stdlib.h>
int pop(void) { return rand()&3; }
int tos=0x123456;
typedef int (*PZ)();
typedef int (*PN)(int, ...);
PZ pz;
PN pn;
void runproc(void) { // RUNPROC ( .. fa n -- ret )
int p1, p2;
switch (pop()) {
case 0: pz=(PZ)tos;
tos=pz();
break;
case 1: pn=(PN)pop(), p1=tos;
tos=pn(p1);
break;
case 2: pn=(PN)pop(), p2=pop(), p1=tos;
tos=pn(p1,p2);
break;
default: tos=-21; }
}
int main(void) {
runproc();
return tos;
}
Gosh, I must have been blinded by our recent thunderstorm...
Thank you! :) :) :)
Quote from: Akko on June 01, 2025, 09:34:04 PMGosh, I must have been blinded by our recent thunderstorm...
... but of course ... the famous thunderstorm excuse... ;D