Does bool pass by value guaranteed to be efficient?

If sizeof(bool) == 1

, then passing by value is efficient because it bool

fits into a register (assuming a standard calling convention is accepted). However, it sizeof(bool)

is implementation-defined. So, is it bool

always guaranteed to be more efficient when passed by value rather than by reference? Are there any guarantees for upper bounds on sizeof(bool)

?

+3


source to share


1 answer


The C ++ and C standards are not meant to protect you from maliciously bad implementations.

Just. You must trust that your implementation will not be bad. If so, don't use it.



In this particular case: Any implementation that makes copying built-in integer types expensive, even if technically compliant, violates the performance of tons of the real world, and therefore may be considered maliciously bad.

So, to make the answer explicit: No, it is not guaranteed by the standards because it is outside their scope. However, this is guaranteed by the limitations of the real world.

+6


source







All Articles