The code below gives exactly the error message which I wanted to prevent with my code.
I don't understand why the check is redundant and I also don't understand, how the access can be out ouf of bounds.
What's wrong here?
[cpptest.c:14] (warning) Either the condition 'index>=0' is redundant or the array 'board_info[4]' is accessed at index 4, which is out of bounds. [arrayIndexOutOfBoundsCond]
The sizeof-thingy just avoids, that a non-array type is passed into the macro. It's a commonly used technique, not my idea. It will indeed create a compiler error like:
bit-field 'not_an_array' width not an integer constant
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The sizeof-thingy just avoids, that a non-array type is passed into the macro. It's a commonly used technique, not my idea. It will indeed create a compiler error like:
bit-field 'not_an_array' width not an integer constant
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The code below gives exactly the error message which I wanted to prevent with my code.
I don't understand why the check is redundant and I also don't understand, how the access can be out ouf of bounds.
What's wrong here?
[cpptest.c:14] (warning) Either the condition 'index>=0' is redundant or the array 'board_info[4]' is accessed at index 4, which is out of bounds. [arrayIndexOutOfBoundsCond]
Thanks for reporting, I have created a ticket: https://trac.cppcheck.net/ticket/10979
How does that sizeof trick work, is it defining a bitfield?
The sizeof-thingy just avoids, that a non-array type is passed into the macro. It's a commonly used technique, not my idea. It will indeed create a compiler error like:
The sizeof-thingy just avoids, that a non-array type is passed into the macro. It's a commonly used technique, not my idea. It will indeed create a compiler error like: