C interop


externc enables the use of subroutines and structs which are defined/declared in C code.
So they can be used in ESPL1000 code.


externc ESPL1000-function-signature "name-in-c"
externc ESPL1000-struct-declaration "name-in-c"


externc fn sdl_init(int k)~>int "SDL_Init"
externc fn sdl_create_window([char] name, int pos1, int pos2, int width, int height, bool shown)~>SDL_Window "SDL_CreateWindow"
externc fn sdl_get_error()~>[char] "SDL_GetError" 

externc fn sdl_free_surface(SDL_Surface surface) ~> bool "SDL_FreeSurface"

externc struct SDL_Window {} "struct SDL_Window"
externc struct SDL_Surface {} "struct SDL_Surface"
Where to put it

At the top of your .dg file, before any struct/fn definitions.

Does it effect the .c file generated?

No, it is only used for typechecking and symbol tables.

passthrough #include statements

Passthrough #include statements are directly put into the transpiled .c source without any further processing.
The corresponding c structs and subroutines still need to be declared with an externc statement.
The passthrough #include statements are only for gcc.


#include <SDL2/SDL.h>
#include <stdio.h>

//externc stuff

//struct declarations

//subroutine declarations
Do i still need to #include the C headers i use, like in C?

yes, as this reduces the size of the binary, to only include what is needed.

however there could be some exceptions to that.