vendredi 23 septembre 2016

May a standards-compliant C assert() evaluate its argument multiple times?

Is the standard C assert(e) macro permitted to evaluate e multiple times? What about C++11 or later? I don't see any guarantees in the Open Group spec, and the answer isn't apparent to me from some searching (1, 2).

Context: could func() be called multiple times in assert(func() != NULL)?

Yes, I already know this is a bad idea for other reasons: as the glibc manual points out, the argument of assert() won't be evaluated at all if NDEBUG is defined. However, assuming NDEBUG is not defined, is there any guarantee on the maximum number of times e is evaluated?

Question prompted by this one.

Aucun commentaire:

Enregistrer un commentaire