On Mon, 17 Apr 2006 10:32:56 -0700, Bryce Harrington <bryce@...961...> wrote:
On Mon, Apr 17, 2006 at 10:30:57AM -0500, Aaron Spike wrote:
bulia byak wrote:
On 4/17/06, Aaron Spike <aaron@...749...> wrote:
bulia byak wrote:
if (!dt) return;
Please contrast the above with "g_return_if_fail(!dt);".
If there's a difference in behavior, I don't know about it.
Well I think I have the condition flipped, but... :-)
I'm wondering if g_return_if_fail() should be avoided because it is a glib thing. Like I've been told to use regular bool rather than gboolean types. It doesn't seem to save any key strokes either.
In code which doesn't otherwise use any gtk or glib functionality, it'd make sense to not use this. On the other hand, if the code is heavy with gtk calls, like the UI code often is, then it doesn't seem like it'd hurt to use the glib style.
g_return_if_fail() prints a warning on the console before returning. Usually it is used for testing preconditions whose failure doesn't warrant aborting execution.
I would recommend using it in any code where "weak" precondition testing is desired.
Incidentally, the equivalent of
if (!dt) return;
is:
g_return_if_fail(dt);
or
g_return_if_fail( dt != NULL );
Note the inversion.
-mental