Obtain variable name in TLC

조회 수: 6 (최근 30일)
Alexander Sinn
Alexander Sinn 2022년 7월 22일
댓글: Alexander Sinn 2022년 7월 25일
I am creating a TLC file for my S-Function and I would like to produce c-code to determine the size of my vector-output-signal array via the sizeof function.
However, both LibBlockInputSignalAddr(0, "", "", 0) and LibBlockInputSignal(0, "", "", 0) only return a reference to the first element of the output signal, thus, sizeof will only return the size of one element of the corrsponding array:
sizeof testModel_Y.Outport[0]
Instead I would like to achieve:
sizeof testModel_Y.Outport
Is it possible generate this statement using a TLC file?

채택된 답변

Andy Bartlett
Andy Bartlett 2022년 7월 22일
Consider doing it in two parts
bytes = LibBlockInputSignalWidth(0) * sizeof( LibBlockInputSignal(0, "", "", 0) )
  댓글 수: 1
Alexander Sinn
Alexander Sinn 2022년 7월 25일
Thank you for the answer.This is the workaround I am currently using.
I was hoping to eliminate the multiplication but this seems not to be possible.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2022년 7월 25일
In C,
sizeof testModel_Y.Outport
is the size of the pointer contained in testModel_Y.Outport . Multiplying the size of one element by the number of elements is the standard way to measure size of an array in C.
  댓글 수: 1
Alexander Sinn
Alexander Sinn 2022년 7월 25일
According to https://docs.microsoft.com/en-us/cpp/c-language/sizeof-operator-c?view=msvc-170 above code would return the size of the array instead of the pointer: When you apply the sizeof operator to an array identifier, the result is the size of the entire array rather than the size of the pointer represented by the array identifier.
This is also in accord with my testing of this operator.

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

카테고리

Help CenterFile Exchange에서 Target Language Compiler에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by