Quick Question

Apr 17, 2013 at 6:45pm
Just had a quick question about a certain reference. <cerrno> (errno.h)

Just wondering how much this is used during programs? I honestly have never seen it.
Apr 17, 2013 at 6:53pm
I use it sometimes to catch mistakes made by the programmer. If I have function that assumes that a parameter is not null assert(p != nullptr); or within some range assert(pos < size); etc. Never use it to catch invalid input from the user! assert can be disabled by defining the macro NDEBUG so I don't have to pay the cost of these checks when running the real thing.
Last edited on Apr 17, 2013 at 6:55pm
Apr 17, 2013 at 7:00pm
So do you only use it with the assert function?

Also can you show me a short way to use it?
Last edited on Apr 17, 2013 at 7:03pm
Apr 17, 2013 at 8:01pm
Haha ops... My eyes must be getting old. I somehow thought you wrote <cassert>. Well, in that case just ignore what I said.

I have never used errno in C++. I think I have used errno in C but I don't remember really and I don't use C much. I think there are often better ways to signal errors than to use errno.
Topic archived. No new replies allowed.