Wireshark-dev: Re: [Wireshark-dev] How to add a string to the tree

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Tue, 12 Sep 2006 14:37:58 -0700

On Sep 12, 2006, at 12:28 PM, prashanth joshi wrote:

In the following function,
what is pinfo _U_  (pinfo followed by a blank space and then _U_?

_U_ is a macro defined by the Wireshark build process.

If the compiler is GCC 2.0 or a later GCC release, it expands to __attribute((unused))__, which is a way of telling GCC that the variable is unused, so that it won't warn about it.

Otherwise, it's defined as nothing, so that compilers that don't support __attribute((unused))__ won't report an error.

_U_ is mainly used when a function is called through a pointer in a table of some sort, so that, even though it might not use a given argument, other functions pointed to by pointers in that table might use that argument, so the argument can't be removed from the argument list. _U_ is used so that you don't get warnings about that; the more warnings are produced, the harder it is to see the ones that warn of real problems, so suppressing warnings that are known not to report a real problem is important.


I am seeing such kind of variable for the first time.
Can i use instead packet_info * ptr as a formal argument in decode_gtp_chrg_id?

You could, but it'd mean you might get warnings from GCC, if you're using GCC.


And is the calling of function foo( ) correct?

No. The _U_ is only used in the definition of a function or variable, to tag a parameter to the function, or another variable, as unused. It's not used when *using* a variable tagged with _U_. (In fact, if you're using the variable, you don't need or want the _U_; if you're using it, it's obviously used, and you shouldn't tag it as unused.)