Modular C
Interfacing with platform specific libraries
Synopsis:
#pragma CMOD mimic <header.h>
#pragma CMOD typedef [ abbrev = ] external_name
#pragma CMOD define [ abbrev = ] external_name
#pragma CMOD alias [ abbrev = ] external_name
#pragma CMOD defexp abbrev = expression
#pragma CMOD defstruct abbrev = [ struct ] external_name member0 member1 ...
#pragma CMOD defreg expr = regexp
#pragma CMOD defrex expr = regexp
#pragma CMOD link linker_option

Interfacing libraries and platforms can be a tedious task. Therefore Modular C proposes this set of directives to lift external interfaces into modules.

Targeting a specific interface: mimic

The mimic directive receives a C header specification as its argument. Features of this header can then be detected by using the other directives from this set.

#pragma CMOD module proj◼lib
#pragma CMOD mimic <stdlib.h>
#pragma CMOD typedef size = size_t
#pragma CMOD define FAILURE = EXIT_FAILURE
#pragma CMOD define SUCCESS = EXIT_SUCCESS
#pragma CMOD alias allocate= malloc
#pragma CMOD declaration
void* allocate(size s);

This creates an additional interface to features of the standard C library. Namely it mirrors the type size_t as proj◼lib◼size, two macros proj◼lib◼FAILURE and proj◼lib◼SUCCESS, and a function proj◼lib◼allocate. For the latter we give a conventional prototype and an alias directive. This directive ensures that all calls to proj◼lib◼allocate are resolved with the symbol malloc of the standard C library.