且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C99枚举-需要澄清

更新时间:2021-09-22 22:23:07

您的代码应该可以使用。通常,尽管您指出的是可接受的答案,但它是更好的编程实践。***将新类型的声明与这些类型的使用分开。例如,如果您编写了一个用于日操作的库,则可以在该库中包含枚举工作日。但这对定义供程序使用的变量将是一个糟糕的地方。
随着时间的流逝,程序员发现这种分离很有价值。通常,它有助于使代码更具可读性

Your code should work. In general though the accepted answer you point to is better programming practice. It's desirable to separate the declaration of new types from the use of those types. For example if you wrote a library for day manipulation, you might include the enum weekdays in that library. But that would be a bad place to define a variable for your program to use. Over time programmers have found this sort of separation valuable. It generally helps code be more readable