POV-Ray : Newsgroups : povray.off-topic : Undirected ramblings on C++ : Re: Undirected ramblings on C++ Server Time
28 Jul 2024 12:24:43 EDT (-0400)
  Re: Undirected ramblings on C++  
From: Lars R 
Date: 28 Feb 2014 06:54:23
Message: <531078ef$1@news.povray.org>
> I didn't mean references specifically. I just meant the entire language.
> Nobody would try to claim that C++ is small or simple or free of
> surprises. For example,
> 
>    struct Side
>    {
>      Pattern & ThePattern;
>      Side(Pattern p) : ThePattern(p) {}
>    }
> 
> Guess what? This segfaults when I run it. *You* probably see the problem
> immediately, but it took me 24 hours to figure out that there's a single
> missing character there...

Hence every compiler is able to emit a - more or less (depends on the
compiler you use) helpful - warning here.

So it is a good idea to compile always with a high warning level and you
should respect the emitted warnings.

> 
> Today it's references. Last time it was
> 
>   catch (std::exception e)
>   {
>     std::cout << e.what();
>   }

Even better: I wrote code like this:

   if(error)
   {
       std::runtime_error("XY went wrong");
   }

but no exception occured, because ... I forgot to _throw_ the exception. :-)

Lars R.


Post a reply to this message

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