This is a quick reference to .khs syntax, written in format:
- Name of construct
- C construct
- Corresponding KDirect construct
Reference
- Enum
- typedef enum { A, B = 5, c } Foo; // defined in "Foo.h"
- #include "Foo.h" (...) enum Foo { A, B, c};
- Abstract pointer without finalizer
- struct Bar {(...)}; Bar *...
- Bar *;
- Abstract pointer with finalizer
- struct Bar {(...)}; Bar *...; void freeBar(Bar *);
- Bar * finalizer freeBar;
- Typedef
- typedef long SomeInt; typedef char CBool;
- typedef Int SomeInt; typedef Bool CBool
- C struct
- typedef struct { int a; char *b; SomeInt c; } Foo; Foo *...
- struct Foo { int a; string b; SomeInt c; };
- Foo *fun(char *r);
- Foo *fun(string r);
- Functions
- int foo(Bar *a, int b, char *c, Foo d);
- int foo(Bar *a, int b, string c, enum Foo d);
- Functions returning string which should be freed
- char *foo(int a); { (...) char *s; s = foo(5); (...) free(s); }
- [free] string foo(int a);
- Functions returning a constant string - not to be freed
- char *foo(enum Foo a); { (...) char *s; s = foo(5); }
- [nofree] string foo(int a);
The default is nofree.
- Functions returning a structure pointer
- Pointer *foo(int a);
The programmer has to call an appropriate C function to free this pointer