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

Do not allow negative interrupt pins #41

Closed
wants to merge 1 commit into from
Closed

Do not allow negative interrupt pins #41

wants to merge 1 commit into from

Conversation

baruch
Copy link

@baruch baruch commented Dec 18, 2017

NOT_AN_INTERRUPT is defined as -1 and might be passed to the function if used as a parameter for the attachInterrupt and detechInterrupt functions.

NOT_AN_INTERRUPT is defined as -1 and might be passed to the function if used as a parameter for the attachInterrupt and detechInterrupt functions.
@MCUdude
Copy link
Owner

MCUdude commented Dec 18, 2017

I agree that allowing -1 to be passed to the function is not a good idea, but the PR adds one more query. It all adds up, so I rather prefer to use.

if(interruptNum == EXTERNAL_INTERRUPT_0)
{
// code
}

@baruch
Copy link
Author

baruch commented Dec 18, 2017

Because the code is compiled with optimizations and assuming that the input is a constant the actual comparison is eliminated and also the entire code is eliminated if the incorrect value is passed.

That said, your comparison method is just as valid for this case (single pin supporting INT0).

As an aside, my personal preference is to avoid the nested if with:

if (interruptNum != EXTERNAL_INTERRUPT_0)
    return;

at the start, this also means you only need a single ifdef SAFEMODE as well.

@MCUdude
Copy link
Owner

MCUdude commented Dec 18, 2017

Good idea! Will commit this change very soon 👍

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

Successfully merging this pull request may close these issues.

None yet

2 participants