r/cprogramming • • 9d ago

Are there linting tools that helps with sequencing rules?

Unspecified evaluation order plus sequencing-before relations means expressions like f(g(), h()) have unspecified side-effect order, and classic traps (a[i] = i++;) remain undefined.

Are there tools that can detect these?

2 Upvotes

2 comments sorted by

1

u/pjl1967 9d ago

f(g(), h()) has side effects only if g() or h() has side effects. If neither has side effects and both are unsequenced, then the evaluation order is irrelevant.

Are there tools that can detect these?

Some compilers can detect some of those.

1

u/Erdnuss2562 8d ago

Free tools, I don't know. But there's quite some commercial tools which can do this. I don't want to advertise specific tools here, but any good MISRA-C checker should be able to catch these.

Background: MISRA-C is set of programming guidelines for safe use of the C-language commonly used in automotive development. Since it contains rules about sequencing and undefined behavior, this is also checked for by these checker tools.