3

Is the given example:

uint32_t i = 0U;
uint32_t arr[5U] = { 0U };
uint32_t b = arr[i++];

Anyhow not compliant with any Misra rules? Can one use pre increment and post increment inside of array indexing? Rule 12.1 is not clear to me about that.

Łukasz Przeniosło
  • 2,725
  • 5
  • 38
  • 74
  • 1
    This could be ambiguous to a nonzero number of reasonably well-trained readers and maintainers, so I'd separate it. I don't have any case studies to support this. This is off the cuff. `uint32_t b = arr[i]; i++;` – JohnFilleau Mar 18 '22 at 13:44
  • I would expect there's a rule that you can't do 2 things at the same time on one line. – KamilCuk Mar 18 '22 at 14:02
  • @KamilCuk How about a line like `for (i = 0; i < 42; ++i) {` ? – Adrian Mole Mar 18 '22 at 14:04
  • 1
    `Rule 12.1 is not clear to me about that.` which MISRA version? From 2012, there are Rule 13.1 and 13.3 , that I believe you are close to braking. – KamilCuk Mar 18 '22 at 14:09
  • Yes, 13.1 and 13.3 seem to be close but I still cannot tell. – Łukasz Przeniosło Mar 18 '22 at 14:11
  • Do you have a misra linter you can run it through and see if it barfs? – JohnFilleau Mar 18 '22 at 14:29
  • 2
    Still a good question. I hope people coming across this don't equate "closed" with "bad" and downvote. I'd like to see dependability and process questions on the hot-questions sidebar more often if I could. – JohnFilleau Mar 18 '22 at 14:37
  • It's not a great duplicate, my answer there was quite specific to that other question. If this is still unclear, let me know. Though please clarify if you are using MISRA C 2004 or 2012. – Lundin Mar 21 '22 at 07:40

0 Answers0