2

I am looking at the C23 draft standard, but I think this would apply in C11 as well. There are several guarantees about sequence points in relation to function calls in C, such as before the return of any library function and between sorting and search algorithm calls to comparison functions. I feel like I am missing something, as my understanding says we don't need these guarantees because we have 6.5.2.2.8:

"There is a sequence point after the evaluations of the function designator and the actual arguments but before the actual call. Every evaluation in the calling function (including other function calls) that is not otherwise specifically sequenced before or after the execution of the body of the called function is indeterminately sequenced with respect to the execution of the called function."

This implies as I understand it a sequence point (or the same effect) before the return of any library function and between any comparison function calls. So we don't need those specific guarantees.

Is this a (somewhat confusing) redundancy, or am I missing something?

EDIT: The comments below give two good reasons for the guarantee for library function returns: a library function may be a macro or may be written in assembly. However, the question still stands in relation to the guarantee that comparison function calls are sequence point separated from eachother (and from element movements in the case of sorting). This is only one redundant assurance at this point, so maybe it is just redundant and there is nothing more to it.

17
  • 4
    Standard library routines may be implemented as function-like macros, so a specific guarantee that a “standard library routine” finishes with a sequence point may cover the macro case when the generic guarantee for expressions in return statements in functions does not. (Semi-speculating, do not have my references conveniently at hand.) Commented May 23 at 4:40
  • 3
    I think the reason is function-like macros as well. C23 7.1.4 lists a number of requirements that such macros are guaranteed to fulfill and next to that they say (7.1.4 §3) "There is a sequence point immediately before a library function returns."
    – Lundin
    Commented May 23 at 6:51
  • 1
    Some of the library functions might be written in assembly, and not have any return statement in them.
    – BoP
    Commented May 23 at 7:52
  • I would read the "sequence point between comparison function calls" promise as ruling out parallel sort/search algorithms that might make concurrent calls to the comparison function (e.g. from multiple threads), or might call it concurrently with rearranging the array. So it is safe for your comparison function to write to static variables, or inspect other elements of the array, without potentially causing a data race. Commented May 23 at 23:32
  • Similarly, "sequence point before return of the library function" could be taken as a promise that the effects are actually complete when the call returns, as opposed to still running in some background thread. I'm not sure if that's the main intent, though. Commented May 23 at 23:33

0

Browse other questions tagged or ask your own question.