Programming Tips-Checking incoming parameters

Source: Internet
Author: User

Header File Definition section:

#define HAL_LED_1 0x01
#define HAL_LED_2 0x02
#define HAL_LED_3 0x04
#define HAL_LED_4 0x08
#define Hal_led_all (Hal_led_1 | Hal_led_2 | Hal_led_3 | Hal_led_4)

To pass in a parameter when the function is called:

Halledset (hal_led_1, hal_led_mode_on);

Check for parameters when the function is implemented:

Uint8 Halledset (uint8 LEDs, uint8 mode)

{

......

LEDs &= Hal_led_all; The purpose of checking the parameters can be achieved here

......

}

--------------------------------------------------------------------------------------------------------------- -----------------------

Use this technique as much as possible in future programming, which plays an important role in the robustness of the program.

Programming Tips-Checking incoming parameters

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.