

Perils of C++ debugging: Petrifying functions - mbrubeck
http://www.yosefk.com/blog/the-c-sucks-series-petrifying-functions.html

======
fauigerzigerk
The short version:

He hates C++ and C++ debuggers

Creating huge objects on the stack makes a program dump core due to a stack
overflow, depending on the default stack size of the operating system. So a
program that used to run OK might suddenly crash after an OS update and the
error output wouldn't be very helpful.

~~~
loup-vaillant
You may have missed the paragraph about books pretending C++ is high level. My
understanding is that he hates _that_ , not necessarily C++ itself. I see this
rant as yet another proof that C++ is as low level as C.

I think the sooner we admit this simple fact, the sooner we will be able to
see C++ for what it is: a niche language, probably not worth it's huge spec.

~~~
thras
I've written low-level C++ calling functions from Fortran and doing all sorts
of magic to do out-of-core matrix calculations.

I've written high-level C++. Generic code with all my objects cleaning up
after themselves.

So my experience is that C++ is a large language that allows programming in
many niches.

~~~
gcv
_Generic code with all my objects cleaning up after themselves._

Are you sure they really cleaned up after themselves, and you don't have a
subtle memory leak waiting to happen because of some unnoticed and rare and
disastrous problem with the order in which your destructors get called? :)

~~~
sorbits
With proper overloads you can easily track your memory usage or even which
instances are leaked.

So yes, C++ is low-level (it does after all include C), but it has features to
abstract away tedious details — this allows higher level programming but being
in control of how the abstractions are implemented, as there are many
performance trade-offs in choosing (implementation of) abstractions, and that
is what makes C++ such nice language for software where performance is
important.

------
wwalker3
He may be using the wrong debugger. When I recreate and run his project in
Visual Studio, I get this error:

Unhandled exception at 0x00b31747 in Bogus.exe: 0xC00000FD: Stack overflow.

The debugger points you to the offending line in a well-commented assembly
routine described as ";_chkstk - check stack upon procedure entry".

It's immediately obvious this is a stack overflow, which takes you past the
first half of his long article. However the second part of the article is
still valid -- you still have to track down which of your objects is the big
one.

------
rwmj
I wonder here if the problem is really just the small default stack size on
Linux. In fact, why _is_ the stack limited to 8MB by default?

(I'm no fan of C++, but I suspect a number of languages that allow general
stack allocated objects could fail in the same way).

~~~
pavlov
8 MB is also the default on Mac OS X. That's for the main thread -- for other
threads (at least those created by the standard pthread mechanism), it's only
512 kB:

<http://developer.apple.com/mac/library/qa/qa2005/qa1419.html>

------
asdlfj2sd33
As a long time C++ programmer is very much appreciate expert C++ advice, even
if it comes from someone who hates C++.

This was great, and I would like to add that any good programmer should know
that it is easily possible to run out of stack space, especially with
recursion.

------
DanielBMarkham
This reminds me of a guy I knew who spent all the time working on his car. All
day long, and all night, he'd be outside underneath banging away at something.

I asked him once, "say, you must really like your car"

He said, "Hell no! This POS! Can't stand it. It's a wonder it even runs for
one day without my having to tinker with it"

You have to really love something a lot to have an entire series of articles
about how bad it is.

And as far as the specifics of this article, it's only so much noise. C++ lets
me shoot myself in the foot because different operating systems have different
stack sizes and nobody told me about it.

Okay -- welcome to the big leagues, kid, where we play without nets.

~~~
mbrubeck
It's not just the articles on his blog; yosefk is also the author of the C++
FQA Lite: <http://yosefk.com/c++fqa/>

He probably hates C++ more than anyone in the universe. (And probably knows
more about it than anyone except veteran C++ implementers and committee
members.)

~~~
DanielBMarkham
Yes I thought this author was a rerun -- I remember his FQA being posted here
a year or so ago.

The opposite of love is not hate; it's ambivalence. So he must really still
carry a torch for the old girl.

~~~
mbrubeck
From a different post: _"...because that would offend C++, The Hate Of My
Life, who does have an ANSI standard. Relax, darling. It’s you, and only you,
that I truly hate. The others mean nothing to me."_

[http://www.yosefk.com/blog/python-teaching-kids-and-
biting-b...](http://www.yosefk.com/blog/python-teaching-kids-and-biting-bits-
dont-mix.html)

