C interoperability and raw C islands
C headers, libraries, functions, pointers, arrays, structs, unions, enums, typedefs, function pointers and platform APIs remain available. Includes do not require NanoC to parse the declarations in a header. Link through the C compiler's normal flags, for example nanoc build main.nc --cflag -lm. C++17 remains a secondary output target, with no additional NanoC C++ type subsystem.
+ <stdlib.h>
f main()
ptr: ptr = malloc(128)
if ptr == NULL
< 1
free(ptr)
< 0#include <stdlib.h>
int main(void) {
void *ptr = malloc(128);
if (ptr == NULL) {
return 1;
}
free(ptr);
return 0;
}@c consumes a balanced braced island, an indented island, or a quoted C source string. The payload bypasses NanoC expansion and output reformatting. Indented and quoted islands can represent preprocessing alternatives whose physical braces do not balance; braced islands require balanced delimiters. Assembly inside raw C is the C compiler's responsibility. Dedicated NanoC @asm and @bt produce removal diagnostics. Raw C is not portable merely because NanoC can pass it through.
@c {
static int apply(int (*fn)(int), int x) { return fn(x); }
}
f twice(x: i32) i32
< x*2
f main()
`int (*fn)(int) = twice;`
< apply(fn,21)!=42
static int apply(int (*fn)(int), int x) { return fn(x); }
int twice(int x) {
return x*2;
}
int main(void) {
int (*fn)(int) = twice;
return apply(fn,21)!=42;
}