C language Implementation of C + + classes

Source: Internet
Author: User

  

typedef struct _S_GPIO gpio;typedef struct _s_gpio{    uint32_t gpiox;    uint32_t Gpio_pinx;    void (*init) (GPIO *gpio);    void (*toggle) (GPIO *gpio);} gpio;static void _s_gpio_init (Gpio *gpio) {rcu_periph_clock_enable (LED1_GPIO_CLK);    Gpio_init (Gpio->gpiox, gpio_mode_out_pp, Gpio_ospeed_50mhz,gpio->gpio_pinx);} static void _s_gpio_toggle (Gpio *gpio) {    gpio_octl (gpio->gpiox) ^= (uint32_t) Gpio->gpio_pinx;} Gpio new_outport (uint32_t gpiox,uint32_t gpio_pinx) {    Gpio temp;    Temp.gpiox = Gpiox;    Temp.gpio_pinx = Gpio_pinx;    Temp.init = _s_gpio_init;    Temp.toggle = _s_gpio_toggle;    Temp.init (&temp);    return temp;} GPIO LEDs; LED = New_outport (gpiof,gpio_pin_6);    while (1)    {        delay_1ms (+);        Led.toggle (&led);    }

This implementation of C + + classes can simplify code duplication or make the code more structured.

C language Implementation of C + + classes

Related Article

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.