Replacing arrays access variables with the right integer type

前端 未结 2 1748
清酒与你
清酒与你 2021-01-06 09:27

I\'ve had a habit of using int to access arrays (especially in for loops); however I recently discovered that I may have been \"doing-it-all-wrong\" and my x86 system kept h

2条回答
  •  暖寄归人
    2021-01-06 09:44

    clang and gcc have -Wchar-subscripts, but that'll only help detect char subscript types.

    You might consider modifying clang or gcc (whichever is easier to build on your infrastructure) to broaden the types detected by the -Wchar-subscripts warning. If this is a one-pass fix effort, this might be the most straightforward way to go about it.

    Otherwise you'll need to find a linter that complains about non-size_t/ptrdiff_t subscripting; I'm not aware of any that have that option.

提交回复
热议问题