Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mstimer return value bug #185

Open
AndyLindsay opened this issue Mar 18, 2019 · 1 comment
Open

mstimer return value bug #185

AndyLindsay opened this issue Mar 18, 2019 · 1 comment

Comments

@AndyLindsay
Copy link
Contributor

AndyLindsay commented Mar 18, 2019

Nice catch from a customer:

The mstime_start function is supposed to return a nonzero number if successful, or zero if unsuccessful, as this screenshot of the documentation shows:

However, I noticed that the code for the function is:

int mstime_start()
{
  mstime_stop();
  cog = 1 + cogstart(ms_timer, NULL, stack, sizeof(stack));
}

which does not have any return statement at the end. I think that the code for this function should instead be:

int mstime_start()
{
  mstime_stop();
  cog = 1 + cogstart(ms_timer, NULL, stack, sizeof(stack));
  return cog;
}
@zfi
Copy link

zfi commented Mar 19, 2019

I'm pretty sure that the the function will return the value of the last statement in the function since the function is declared to return a type int. A quick test will verify the behavior. Providing an explicit return does make it much more readable.

Since 'cog' is not declared, I'm assuming that it is defined elsewhere and you are setting it in this function. Otherwise, you could just return the result of the computation and eliminate the variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants