erpc icon indicating copy to clipboard operation
erpc copied to clipboard

Is it possible to add defines into IDL

Open tmordeko opened this issue 3 years ago • 6 comments

Hi,

Is #define supported by IDL ? we are currently substituting defines with const uint32 BLA_BLA_DEF = 100; if it is not supported then it will be very helpful

Thanks in advance, Tzvika

tmordeko avatar May 31 '22 11:05 tmordeko

Hi @tmordeko currently defines are not supported. Can you explain why to use defines instead of variables? Using variables is helpful for compilers to identify possible issues. What you can do is define variables as external and include file where you have defines for values.

Hadatko avatar May 31 '22 11:05 Hadatko

Hi @Hadatko ,

To avoid the extra space, for example we use these "defines" within @max_length annotation Can you please elaborate on your proposal "What you can do is define variables as external and include file where you have defines for values."

Regards

tmordeko avatar May 31 '22 11:05 tmordeko

mydefines.h: #define MY_FIRST_MACRO 10

idl: @include("mydefines.h") program ....

@external const uint8_t MY_FIRST_MACRO=10

Hadatko avatar May 31 '22 11:05 Hadatko

Thanks ! Please consider to add defines into IDL in the future

tmordeko avatar May 31 '22 11:05 tmordeko

Hi @Hadatko

Not sure your approach is applicable to my use case, for example we use these defines (previously defined as const vars) to indicate param's max length in function's IDL declaration, for example MY_MAX_SIZE below:

@include("my_include.h") MY_FUNC(in uint32 param1, in uint32 data_length , in binary data @length(data_length) @max_length(MY_MAX_SIZE))

In my_include.h

#define MY_MAX_SIZE 100

Now after moving to .h @include annotation I get the following error msg: "error: line XX: The parameter or member named by a max_length annotation must exist."

In previous implementation it worked:

const uint32 MY_MAX_SIZE = 100;

MY_FUNC(in uint32 param1, in uint32 data_length , in binary data @length(data_length) @max_length(MY_MAX_SIZE))

Please advise

/Tzvika

tmordeko avatar Jun 01 '22 09:06 tmordeko

Hi @tmordeko in IDL you are missing external definition for MY_MAX_SIZE

You need define MY_MAX_SIZE twice. Once in .h file and once in IDL as external

Hadatko avatar Jun 01 '22 10:06 Hadatko