digitalmars.D.learn - importC function pointers under windows: DMD v2.112.0
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.
Apr 20
On Monday, 20 April 2026 at 16:04:32 UTC, DLearner wrote:Consider:[...]To me, there is no 'void' as the void* ptr has been expressly cast to a proper pointer type.The same situation seems to occur with: ``` #include <stdio.h> void ccallee3(void) { printf("ccallee3: Entered (written in C)."); printf("\n"); printf("ccallee3: Exiting..."); printf("\n"); return; } ``` called by ``` // Calling C subfn via FP // dmd -betterC cmst3.c ccallee3.c #include <stdio.h> extern void ccallee3(void); void main(void) { typedef void (*ccallee3typPtr)(void); ccallee3typPtr wkPtr; printf("main: Entered (written in C)."); printf("\n"); printf("main: About to call ccallee3 via FP..."); printf("\n"); wkPtr = &ccallee3; (*(wkPtr))(); // *(wkPtr)(); printf("main: Returned from ccallee3."); printf("\n"); printf("main: Exiting...\n"); return; } ``` Which is slightly simpler.
Apr 20
On Monday, 20 April 2026 at 17:13:26 UTC, DLearner wrote:On Monday, 20 April 2026 at 16:04:32 UTC, DLearner wrote:[...]Consider:[...]To me, there is no 'void' as the void* ptr has been expressly cast to a proper pointer type.The same situation seems to occur with:[...] There is no problem (apart from my misunderstanding C's parsing rules). Sorry for the noise.
Apr 21








DLearner <bmqazwsx123 gmail.com>