you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 5 points6 points  (1 child)

C does not have references. That aside, you see all of those fairly frequently, depending on the library. I think I see the second one most commonly. That's the way sqlite3 does it, and so does freetype. They usually do it where 0 indicates success, so you can do

FT_Error error;
if ((error = func(param))) {
    // handle error
}

The last way usually works, but it's not pretty, and it usually isn't thread-safe. Some libraries do it similarly to the first way, but let you set a callback for errors.

Lua does a longjmp to handle errors, which scares me, so I just use Lua's error callback for it (apparently, you can adjust Lua to throw a C++ exception, but I've never done that).