Function return value type: Enumeration type

Source: Internet
Author: User

Function return value type: Enumeration type
Enumeration is a good thing. Like a struct, enumeration can define a data type. However, enumeration has the advantage of specifying the initial value by default. There is a project that involves the CPU card. The card has a status such as error, power-on, and DF01 directory. If you define these variables separately, you need to use many variables. Here there is a rule: the CPU card can only be one of the several states at the same time. In this way, we can define an enumerated type variable, such as: // identify several states of the ic: typedef enum {ICC_ERROR, ICC_NO_EXIST, ICC_EXIST, ICC_POWER_OFF, ICC_POWER_ON, lead} t_IccStatus; t_IccStatus getIccStatus; in a program, this enumerated variable can be used to identify the CPU card status in the entire project. It is concise, clear, and saves many global variables. The return value type is enumeration. Generally, a function has a return value. In a project, if a special number is defined at each error point, in main, the returned value is a unique value, so that the error point can be quickly located. In combination with the above enumeration, the return value of the function is defined as the enumeration type. When defining enumeration, you can use English words to define different return values. In this way, during debugging, be well-known and quickly find error points to get twice the result with half the effort.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.