Ethereal-dev: Re: [Ethereal-dev] README.developer - if (tree)

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Tue, 16 Dec 2003 14:26:20 -0800

On Dec 16, 2003, at 2:12 PM, Devin Heitmueller wrote:

How about this -- can we replace the function proto_tree_add_X() with a
macro that checks to see if the first argument is non-null?

Yes, as long as "proto_tree_add_X" doesn't take a variable number of arguments. (C89 doesn't support macros that take a variable number of arguments.)

Unfortunately, if "X" is "text" or includes the word "format", "proto_tree_add_X" *does* take a variable number of arguments.

This would
eliminate the need for the developer to add the "if (tree)" before every
call.  We would get the benefits of not having to do the stack loading,
but also not have to clutter the code with the if statements.

If all you're doing is

	...

	if (tree)
		proto_XXX_add_YYY(...)

	...

rather than

	if (tree) {
		proto_XXX_add_YYY(...);
		proto_ZZZ_add_WWW(...);

			...
	}

then the only advantage of the "if (tree) is that you skip a procedure call.

The idea is to use "if (tree)" to surround a large *block* of code, so you can skip it all.