Is if(TRUE) a good idea in C?

后端 未结 17 3460
忘了有多久
忘了有多久 2021-02-19 01:19

In the C programming language, it is my understanding that variables can only be defined at the beginning of a code block, and the variable will have the scope of the block it w

17条回答
  •  不思量自难忘°
    2021-02-19 01:26

    C99 allows you to declare variables almost anywhere. However, refrain from doing it without a very good reason. Try first to split your function into smaller (possibly inline) functions.

    The only place where such a thing might make sense is when you have a variable that is initialized in the middle of your function, e.g. similar to creating an object in C++.

提交回复
热议问题