3

The function-like macro is

#define ARRAYSIZE(_Array)  ((sizeof(_Array)) / (sizeof(_Array[0])))

The error shown is:

Error[Pm154]: in the definition of a function-like macro, each instance of a parameter shall be enclosed in parenthesis (MISRA C 2004 rule 19.10)

Lundin
  • 195,001
  • 40
  • 254
  • 396
Utkarsh
  • 31
  • 5

1 Answers1

6

It's just pedantically saying that you should be doing this sizeof( (_Array)[0] ). Postfix operators have very high precedence so it's unlikely to become an actual problem.

Pedantically you should also use 0u since the intention is for the 0 to correspond to an unsigned type (size_t).

Also please note that leading underscore followed by upper-case letter is reserved for any use in the C language, MISRA or no MISRA.

I'd replace this whole macro with:

#define ARRAY_SIZE(array) ( sizeof(array) / sizeof *(array) )

Should be compliant both to the C language and MISRA-C.

Lundin
  • 195,001
  • 40
  • 254
  • 396