Can't import some LibC functions?

Just starting out? Need help? Post your questions and find answers here.
nsstudios
Enthusiast
Enthusiast
Posts: 274
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

Can't import some LibC functions?

Post by nsstudios »

Hi everyone,

I hope you're staying safe.
I have been experimenting with importing LibC functions, and ran into two problems so far, so I'm wondering why they occur and if there's a way to make them work properly.
1. atexit: invalid memory access at 0.

Code: Select all

; extern	int	atexit(void(*)(void));
ImportC ""
atexit(*f)
EndImport
Procedure f()
Beep_(800, 30)
EndProcedure
Debug atexit(@f())
I guess the weird way it expects the function pointer is not something PB likes? I have tried both Procedure and ProcedureC and still no change.

2. assert: PureBasic.asm [15]: extrn assert error: reserved word used as symbol.

Code: Select all

; #define	assert(x)	if(x){}else _assert("x")
ImportC ""
assert(expression)
EndImport
Debug assert(Bool(2+2=4))
I know there are alternatives to both of these functions (assert is technically a macro I guess, but doing as "__assert" doesn't really do anything different), so I'm curious why they don't work while a lot of other functions do, and if there's something I'm missing?
Can we even import C macros or interface with a void(*)(void) argument?

Thanks.