add ARRAY_SIZE macro and make use of it#11865
Conversation
|
I don't like macros... But we can discuss this again. If we go for this, I'd opt for "ARRAY_SIZE()". It's what Linux is using. |
|
@benpicco Did you know that Coccinelle (Semantic Patch) has an example precisely for this? |
|
In fact, this is my first experience with You may have missed a few more chances for The |
|
spatch can even do better by adding this It then finds possible changes like this: |
|
Notice that your sed command can be improved a bit.
Try this and you'll have more hits, for example in |
|
@benpicco Have a look at my
|
|
There's one more place to look at: |
|
I added all your findings, except for |
keestux
left a comment
There was a problem hiding this comment.
It looks OK to me.
I've used spatch as well to find potential candidates for the macro, and most of these candidates have been incorporated.
I did not do much testing (yet), only visual inspection. That isn't hard to do, except that there are so many. I'm hoping that our testing system will catch introduced errors, if there happen to be any.
|
So squash? |
|
@benpicco can you squash the commits with "fixup!"? Maybe you want to do more squashing? It's up to you. |
|
@benpicco I've added the label for murdock. As you can see murdock failed because of a merge conflict. Can you have a look? I would say "rebase onto master", which is probably the best strategy. No? |
Yes, but you don't need Murdock to see that. The conflict is also notified by GitHub. ;-) |
I think there are macros and macros. They can be annoying and actually hinder debugging when they hide something like 10 lines of code and changes of variables. But this kind of macros with just one input and a clear output are fine (and actually helpful) IMHO. |
|
Touching all those files seems to have triggered some new Travis checks. I'll make a separate pull request for those then. Since embUnit appears to be external code, I didn't want to touch if it's not necessary, so it's easier to import new versions in the future. |
It is allowed to piggy-back style and CI fixes to a PR. No need to open a separate one. |
|
(just keep 'em in separate commits, so 👍)
Good thinking, however it was meddled with before and I doubt there are any changes happening upstream (the last update is from 2004). |
|
With all the required includes of |
|
Yea that's what stopped me from fixing the remaining build errors. I think I world have less hesitation if it were just called |
|
Now this one I don't get. Or is cppcheck taking that |
44c32bb to
01dffcf
Compare
|
Rebased again & made |
|
Great |
Yes, it takes every path in account (so the assert is ignored for the |
|
Hmm, I should have hit the Merge button yesterday :-( But, it was late and I wanted to check one more thing. @benpicco Can you have a look? |
This makes cppcheck happy.
|
Let's try it again! |
Contribution description
All throughout RIOT the construct
sizeof(a) / sizeof(a[0])is used to determine the number of elements in an arraya.For the sake of DRY and readability, this introduces an
ARRAYSIZEmacro that does just that, without having to spell out the formula each time.Testing procedure
Conversion was done with
sed -ri 's/sizeof\((.*)\)\ \/ sizeof\(\1\[0\]\)/ARRAYSIZE\(\1\)/g'No functional change is expected.