[prev in list] [next in list] [prev in thread] [next in thread]
List: wireshark-dev
Subject: Re: [Wireshark-dev] Style question passing boolean parameters
From: Guy Harris <guy () alum ! mit ! edu>
Date: 2012-06-22 20:07:19
Message-ID: B8E1EA35-D016-48F6-9000-08739D7BD30F () alum ! mit ! edu
[Download RAW message or body]
On Jun 21, 2012, at 12:33 PM, Guy Harris wrote:
> 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.
Also, I'm not sure whether any compilers would warn about
if (cf_save_packets(&cfile, file_name8->str, filetype, DONT_DISCARD_COMMENTS, \
NOT_COMPRESSED, DONT_REOPEN) != CF_OK) {
where the various indicators aren't passed in the right order, because enums aren't \
"real" data types in C, so if you don't remember the order correctly, the compiler \
might not warn you about it.
Bitwise OR is commutative, so the difference between
if (cf_save_packets(&cfile, file_name8->str, filetype, \
NOT_COMPRESSED|DONT_DISCARD_COMMENTS|DONT_REOPEN) != CF_OK) {
and
if (cf_save_packets(&cfile, file_name8->str, filetype, \
DONT_DISCARD_COMMENTS|NOT_COMPRESSED|DONT_REOPEN) != CF_OK) {
is a matter of taste rather than of correctness; there's no order of indicators that \
you have to remember. \
___________________________________________________________________________ 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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic