Ethereal-dev: Re: [Ethereal-dev] Patch: value_string convenience macros

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

From: "Peter J. Creath" <peter-ethereal@xxxxxxxxxx>
Date: Sun, 22 Feb 2004 18:23:31 -0500
Michael Tuexen wrote:
It saves to append the ',' at the end of VS_DEF.

I actually intentionally omitted the comma to make it a bit easier to intersperse normal definitions with VS_DEF()s. E.g.:

const value_string my_vals[] = {
  VS_DEF(ONE),
  VS_DEF(TWO),
  VS_DEF(THREE),
  { 314, "PI" },
  VS_DEF(FOUR),
  VS_END
};

Guy Harris wrote:
They let you define value_string arrays in a somewhat more convenient fashion
when dealing with enums:

...or when dealing with #defines...

...but *ONLY* in those cases where the string corresponding to the value
happens to be the enum or #define name, which is very often not the case
for value_string tables

While this is often true for verbose dissection, I've found it's often quite useful to have the formal (#defined) names listed as well. So I often have a my_short_vals[] comprised of just VS_DEF()s, followed by a my_long_vals[] with the more explicit, informative names. This lets someone who knows the protocol well read it quickly (and unambiguously), and it provides clarity for the rest of the world.

	-P