POV-Ray : Newsgroups : povray.off-topic : Error mesage : Re: Error mesage Server Time
7 Sep 2024 19:14:05 EDT (-0400)
  Re: Error mesage  
From: Warp
Date: 5 May 2008 04:41:57
Message: <481ec855@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Yeah. I'd just been thinking about Warp's example earlier that needed 
> "weak" references to actually not "leak" resources. I was trying to 
> figure out how C++ handled it, if at all.

  Stream manipulation flags are one thing which is shamefully bad designed
in C++, and I really don't understand what they were thinking of.

  A few flags are set only until the next output action which is affected
by that flag (after which it's automatically reset). However, the rest are
permanently set until they are explicitly reset. This means that these
flags can "leak". For example this may well happen:

std::cout << 10 << std::endl;
foo();
std::cout << 10 << std::endl;

  If foo() calls, for example, std::hex(std::cout), then what is printed is:

10
a

  foo() could alleviate this problem by storing the flags into a variable
at the beginning and then restoring those flogs when it ends, but as we
all know, functions can have surprising exit points. (It's still possible
to make sure that the flags are restored at any exit point by using the
destructor mechanism of C++, but it becomes a bit more laborious. I'm
actually surprised the standard library doesn't offer an class type for
this exact purpose...)

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.