importC function pointers under windows: DMD v2.112.0
DLearner
bmqazwsx123 at gmail.com
Mon Apr 20 16:04:32 UTC 2026
Consider:
```
#include <stdio.h>
void ccallee2(void)
{
printf("ccallee2: Entered (written in C).");
printf("\n");
printf("ccallee2: Exiting...");
printf("\n");
return;
}
```
called by:
```
// Calling C subfn via FP
// dmd -betterC cmst2.c ccallee2.c
#include <stdio.h>
extern void ccallee2(void);
void main(void)
{
void* wkPtr;
typedef void (*ccallee2typPtr)(void);
printf("main: Entered (Written in C).");
printf("\n");
printf("main: About to call ccallee2 via FP...");
printf("\n");
wkPtr = &ccallee2;
(*((ccallee2typPtr)wkPtr))();
// *((ccallee2typPtr)wkPtr)();
// *((ccallee2typPtr)(wkPtr))();
printf("main: Returned from ccallee2.");
printf("\n");
printf("main: Exiting...\n");
return;
}
```
As written, compiles and runs correctly.
But either of the two commented-out alternatives produce:
```
Error: can only `*` a pointer, not a `void`
```
To me, there is no 'void' as the void* ptr has been expressly
cast to a proper pointer type.
More information about the Digitalmars-d-learn
mailing list