In C, does initialising a variable to it\'s own value make sense? If yes, what for?
Allow me to elaborate. In Git sources there are some examples of initialising a varia
For me the only reason of such self-assigning initialization is to avoid a warning.
In the case of your transport.c
, I don't even understand why it is useful. I would have left cmp
uninitialized.
My own habit (at least in C) is to initialize all the variables, usually to 0. The compiler will optimize unneeded initialization, and having all variables initialized makes debugging easier.
There is a case when I want a variable to remain uninitialized, and I might self-assign it: random seeds:
unsigned myseed = myseed;
srand(myseed);