Boost logo

Boost :

Subject: Re: [boost] [system][filesystem v3] Question about error_code arguments
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-10-21 09:18:02

Andrey Semashev wrote:
> Stewart, Robert wrote:
> >>>
> > I wasn't referring to checking the reference or pointer. Rather, I
> > was pointing out that the reference must be bound to something when
> > the default is accepted. Every call using the default implies code
> > that acquires an object or reference to one to which the formal
> > parameter can be bound. That is costlier than simply passing a null
> > pointer unless some compiler magic is involved.
> The call to throws() can be inlined so that the global object
> acquisition turns into loading its address in a register. The
> address is
> known at compile time, so there's little difference between loading a
> zero into a pointer/reference argument and loading a valid
> address into
> a reference argument. No magic needed for this to happen.

If the global object is created before all code calling throws() is done, then its address can be taken safely by multiple threads. Doing so requires compiler/runtime magic.

If the global object is created each time, there's code to create that object for each call accepting the default. I'm not speculating whether that construction is trivial, so there is, at least potentially, a cost per call accepting the default in such a case.

Finally, the zero for a null pointer default can be coded close to the call or even embedded in an instruction. Fetching the address of a global object cannot so optimized, so every call accepting the default incurs a greater cost.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at