Notes from C++ static analysis

Walter Bright newshound2 at digitalmars.com
Wed Jun 26 17:33:58 PDT 2013


On 6/26/2013 4:48 PM, Timon Gehr wrote:
> On 06/27/2013 01:01 AM, Walter Bright wrote:
>> On 6/26/2013 3:56 PM, Walter Bright wrote:
>>> On 6/26/2013 2:47 PM, Paulo Pinto wrote:
>>>> I have been an adept of iostreams since day one and never understood
>>>> why people
>>>> complain so much about them or the operator<< and operator>>
>>>> for that matter.
>>>
>>> Even if you can get past the execrable look of it, it suffers from at
>>> least 3
>>> terrible technical problems:
>>>
>>> 1. not thread safe
>>>
>>> 2. not exception safe
>>>
>>> 3. having to acquire/release mutexes for every << operation rather
>>> than once for
>>> the whole expression
>>
>
> If it's not thread safe, why does it have to acquire mutexes?

It's not thread safe because global state can be set and reset for every << 
operation:

   a << b << setglobalstate << c << resetglobalstate << d;


>> Oh, and the cake topper is IOStreams performs badly, too.
>
> Yes, but that's just a default.
>
> std::ios_base::sync_with_stdio(false);
> std::cin.tie(0);

Yeah, to make it as fast as C stdio you use C stdio. That's a ringing endorsement!


More information about the Digitalmars-d mailing list