Skip to content

Comment on When static makes your C code 10 times fasterparent

Comments

It is mostly about the fact that if the variable is not static, then it's non-local to the translation unit and can be modified from everywhere else. So its value needs to be loaded and a plain and slow division is applied.

Having it local or const makes the compiler able to inline it and do a simple bitwise and with a constant.

So yes, make your variables static const by default (if you really need global).

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.