Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

2 scenarios which is better when declaring int buzzer_shortA(void) and void buzzer_shortB(void)

Melt BrinkMelt Brink Member Posts: 1

I would like to know if there is a difference in the below to function declarations and if there any benefits to using the one or the other. Both Work

//function declarations
int buzzer_shortA(void); // sample 1
void buzzer_shortB(void); // sample 2

//function sample 1 called from main

int buzzer_shortA(void) // long buzzer on
{
gpio_set_state(GPIO0_PORT, GPIO0_PIN, SET);// Turn buzzer on
delay_ms(100);
gpio_set_state(GPIO0_PORT, GPIO0_PIN, RESET);// Turn buzzer off
delay_ms(100);
return(0);
}

//function sample 2 called from main

void buzzer_shortB(void) // short buzzer on
{
gpio_set_state(GPIO0_PORT, GPIO0_PIN, SET);// Turn buzzer on
delay_ms(100);
gpio_set_state(GPIO0_PORT, GPIO0_PIN, RESET);// Turn buzzer off
delay_ms(100);
return;
}

Comments

  • B00B00 Member Posts: 115 ✭✭✭

    No difference in this case. Void function does not need return statement at all.
    You'd want int if you cared about return code and wrote code accordingly.

Sign In or Register to comment.