How is conditional initialization handled and is it a good practice?

后端 未结 5 546
情歌与酒
情歌与酒 2020-12-06 18:46

I am trying to decide between several possible practices. Say, my function has a number of if() blocks, that work on data, that is unique to them.

  • Should I

5条回答
  •  自闭症患者
    2020-12-06 19:14

    For completeness; another, usually less important consideration is stack padding control / packing, which is intuitively more difficult if you don't declare everything upfront.

    See this for more information, although let me emphasize the following paragraph before anyone does anything crazy:

    Usually, for the small number of scalar variables in your C programs, bumming out the few bytes you can get by changing the order of declaration won’t save you enough to be significant. The technique becomes more interesting when applied to nonscalar variables - especially structs.

提交回复
热议问题