Is the timing between the end of a switch statement and the next statement deterministic (independent of path)?

Viewed 85

I'm configuring various GPIO pins on a microcontroller (which initiates a process that I need to time) inside a switch statement and then resetting a timer counter immediately after the end of the switch statement on the assumption that the period between the last instruction of each switch case (presumably some kind of jump or return) and the first statement after the switch will be the same independently of which case was executed.

My question - is there anything in c/c++ specifications that would validate my assumptions or am I over reaching and should reset my timer inside each case explicitly?

1 Answers

the assumption that the period between the last instruction of each switch case (presumably some kind of jump or return) and the first statement after the switch will be the same

This is implementation dependent behavior. Best way to find out what's happening is to look at the assembly code generated and perform some timing profiling on your code.

Related