16.10.1 in an .api file is it possible to "DEFINE" from legacy C #defines


I am legato wrapping public legacy C code which is maintained by others.

There are #defines in the the legacy code which really should drive the legato api definition e.g.
In the api definition MAX_STRING_SIZE = 256 is really defined by the legacy code and could change e.g.


FUNCTION legacyFunctionWrapper

string device [MAX_STRING_SIZE] IN

Legacy code.c

#define MAX_STRING_SIZE 125

Any ideas ?



There’s no way to reference C defines from inside a .api file. This is on purpose – eventually we hope to be able to use other languages (like Java) to access Legato APIs as well.

However you can create an API file from your C header. E.g. something like:

gcc -E -dD some_header.h |sed -r s/[ \t]*#define[ \t]+([A-Za-z][A-Za-z0-9_]*)[ \t]+([0-9]+)[ \t]*$/DEFINE \1 = \2;/;t;d' > some_header.api

should work (assuming you only want #defines which are integers, excluding defines which start with ‘_’). Of course, you will need to rerun this every time your header changes.

1 Like