Embedded coder: How to specify array function input parameter as constant (read only) ?

조회 수: 2 (최근 30일)
A certain MatLab function has an array as an input parameter. The function only reads from that array, it never changes its size or writes to it.
When this function is put through the embedded coder, I get:
extern void stepMeasProcessScan(const emxArray_uint8_T *img, ......
which is good: MatLab recognised that my code never changes the input parameter "img".
But: emxArray_uint8_T is generated as follows:
typedef struct emxArray_uint8_T {
uint8_T *data;
int32_T *size;
int32_T allocatedSize;
int32_T numDimensions;
boolean_T canFreeData;
} emxArray_uint8_T;
So the generated code cannot change any of the members of this struct, because of the "const". But the generated code could change the data pointed to by the "data" and "size" members, because they lack a "const" in their definition.
As a result, copying a "const uint8_T *" into "data" results in a compiler error.
What I need, is something like:
typedef struct emxArray_const_uint8_T {
const uint8_T *data;
const int32_T *size;
int32_T allocatedSize;
int32_T numDimensions;
boolean_T canFreeData;
} emxArray_uint8_T;
Can anybody tell me how to achieve this ?
  댓글 수: 5
Kaustubha Govind
Kaustubha Govind 2012년 8월 1일
편집: Kaustubha Govind 2012년 8월 1일
TAB: I think this would be a MATLAB Coder question either way because Simulink/Embedded Coder uses MATLAB Coder technology to generate code from (Embedded) MATLAB Function blocks.

댓글을 달려면 로그인하십시오.

채택된 답변

Fred Smith
Fred Smith 2012년 8월 1일
This is an oversight in the design. I've created a bug report.
In the mean time, you can work around the problem by using a const cast. Just cast your pointer so that it is not const any more. This is ugly but will allow you to make forward progress.
HTH,
Fred

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by