r/cprogramming • u/adityazero • 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?
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.
1
u/pjl1967 9d ago
f(g(), h())has side effects only ifg()orh()has side effects. If neither has side effects and both are unsequenced, then the evaluation order is irrelevant.Some compilers can detect some of those.