{} , const, , , - . - :
#define CONSTIFY(T, NAME) \
for (bool p00 = true; p00; p00=false) \
for (T p000 = NAME; p00; p00=false) \
for (T const NAME = p000; p00; p00=false)
this should work in both C99 and C ++. Technically, this does not make your original variable const, but creates a new variable with the same contents for the dependent area.
And be careful that in some cases ( breakor continue) this can change the flow of control. But as long as you wrap it around something that is basically the whole body of a function, this should work.
source
share