Wireshark mailing list archives
Re: Style question passing boolean parameters
From: Guy Harris <guy () alum mit edu>
Date: Thu, 21 Jun 2012 12:33:03 -0700
On Jun 19, 2012, at 10:12 PM, Joerg Mayer wrote:
The following commit retriggered an allergic reaction to controlling function
behaviour via booleans:
if (cf_save_packets(&cfile, file_name8->str, filetype, FALSE/*compressed */, FALSE/*discard_comments */,
FALSE/* dont_reopen */) != CF_OK) {
To me, this is sort of unreadable without the comments and ugly looking with
the comments. My favourite nightmare in this regard in wireshark source is
dissect_ieee80211_common which has 4 boolean parameters and no comments anywhere
where it is called.
What ways are there to fix this? Is replacing the boolean types by an enum with
speaking elements a valid solution?
It's one.
Another would be to pass a single flags argument, e.g.
if (cf_save_packets(&cfile, file_name8->str, filetype, NOT_COMPRESSED|DONT_DISCARD_COMMENTS|DONT_REOPEN) !=
CF_OK) {
(with some of the flag values #defined to be 0, so that, regardless of the value of the flag, the value is indicated in
the call).
Fewer arguments means, in a call, either fewer pushes onto the stack or fewer registers required for passing
parameters. I'm not sure whether it's significantly more expensive (or more expensive at all) to test a single bit in
a flags word than to test a Boolean variable on various architectures.
___________________________________________________________________________
Sent via: Wireshark-dev mailing list <wireshark-dev () wireshark org>
Archives: http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
mailto:wireshark-dev-request () wireshark org?subject=unsubscribe
Current thread:
- Style question passing boolean parameters Joerg Mayer (Jun 19)
- Re: Style question passing boolean parameters Stephen Fisher (Jun 20)
- Re: Style question passing boolean parameters Bill Meier (Jun 20)
- Re: Style question passing boolean parameters Guy Harris (Jun 21)
- Re: Style question passing boolean parameters Guy Harris (Jun 22)
