Skip to content

Instantly share code, notes, and snippets.

@chergert
Created November 14, 2012 00:30
Show Gist options
  • Select an option

  • Save chergert/4069376 to your computer and use it in GitHub Desktop.

Select an option

Save chergert/4069376 to your computer and use it in GitHub Desktop.
when to use g_assert and when to use g_return_*if_fail()

When to use g_assert* and when to use g_return* macros

Do use g_assert() when:

  • The function is static inside your implementation
  • If the precondition fails the entire module you have is in an inconsistent state

Do use g_return_{,val_}if_fail() when:

  • For pre-conditions and post-conditions.
  • You are in a public function.
  • You are checking that the caller is using the API correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment