MISRA Discussion Forums
Rule 12.5 - sized and unsized array parameters - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.12 Expressions (https://forum.misra.org.uk/forumdisplay.php?fid=167)
+---- Thread: Rule 12.5 - sized and unsized array parameters (/showthread.php?tid=1256)



Rule 12.5 - sized and unsized array parameters - rgamble - 11-06-2016

Does Rule 12.5 from AMD-1 apply to unsized array parameters (those without a size between the brackets)? E.g.:

Code:
void f(int32_t A[4], int32_t B[]) {
    uint32_t sizeA = sizeof(A);  // Obvious violation of 12.5
    uint32_t sizeB = sizeof(B);  // Violation of 12.5?
}

The snippets in the amplification, rationale, and examples exclusively use sized arrays and the rationale does not seem to apply as strongly to unsized array parameters but the rule does not specify that it only applies to sized arrays or to both sized and unsized arrays. Can you please clarify the intention here?


Re: Rule 12.5 - sized and unsized array parameters - misra-c - 27-06-2016

Rule 12.5 applies to all function parameters declared as "array of type". Array declarators always have an "array type", regardless as to whether the size is present or not (See 6.7.5.2 of the C99 standard). The standard uses the phrases "array type" and "array of type" interchangeably.

Therefore this rule applies to both sized and unsized types and your second example violates 12.5.