Can codegen generate input array size as #define instead of hard coded numbers in function definitions?

17 views (last 30 days)
I have a function which formats some data into a string and returns it. For this example let's say it is something simple like so:
function [formattedString, someStruct] = paramsToString(someStruct)
formattedString = ['a=' someStruct.a ', b=' someStruct.b];
end;
I then use codegen to create "C" code like so:
codegen -config cfg -c -d build -report convertToString.m -args {someStruct}
The generated code looks like this:
void convertToString(const someStructType *someStruct, char_T formattedSomeStruct_data[2750], int32_T formattedSomeStruct_size[2])
To call this from some other C code (not matlab) one has to do this:
char_T formattedSomeStruct_data[2750];
int32_T formattedSomeStruct_size[2];
convertToString(someStruct, formattedSomeStruct_data, formattedSomeStruct_size);
The problem is that to call this code I need to know the max size of formattedSomeStruct_data which is only defined in the function definition itself to be 2750.
I can hard code this number in the function I am calling but that is really bad as I will have to change this every time Matlab code changes.
Is there away to force codegen to put that info into some header file preferably into a #define such that the calling code would like so:
char_T formattedSomeStruct_data[MAX_SIZE_OF_RESULT];
int32_T formattedSomeStruct_size[2]; //This is probably ok as it is always 2 in matlab land.
convertToString(someStruct, formattedSomeStruct_data, formattedSomeStruct_size);

Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!