tag:blogger.com,1999:blog-1016709139053396535.post8754704064491945638..comments2024-03-18T17:34:35.079+00:00Comments on A Smackerel of Opinion: A C for-loop GotchaColin Ian Kinghttp://www.blogger.com/profile/06458723239721015750noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-1016709139053396535.post-21975641723170963012021-04-13T16:15:59.049+01:002021-04-13T16:15:59.049+01:00It should always be "int i;".
On my sys...It should always be "int i;".<br /><br />On my system it takes 8 seconds to count to U32_MAX. There are definitely times when we need to loop over size_t but it's not very common in the kernel. If you're doing a special long loop like this then use a size_t type and call the variable page_idx or something so that everyone knows it's not a regular loop.<br /><br />When you have a huge loop the the type should never be u32. It should be long or long long. There isn't that big of a jump between 2 and 4 million so very few problems are solved by u32.<br /><br />In the kernel when you enable W=3 then GCC tells you to make all your loop iterators into u32. This is terrible advice and leads to a lot of signedness bugs. GCC should be fixed.error27https://www.blogger.com/profile/11173675100058673352noreply@blogger.com