Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jan 2001 09:59:30 -0600
From:      "G. Adam Stanislav" <adam@whizkidtech.net>
To:        Jonathon McKitrick <jcm@shellyeah.org>
Cc:        freebsd-chat@FreeBSD.ORG
Subject:   Re: C style continued.... (Craig and Terry)
Message-ID:  <3.0.6.32.20010123095930.00a14550@mail85.pair.com>
In-Reply-To: <Pine.GSO.4.21.0101231014560.7653-100000@zippy.shellyeah.or g>
References:  <3.0.6.32.20010123091354.009de7c0@mail85.pair.com>

next in thread | previous in thread | raw e-mail | index | archive | help
At 10:16 23-01-2001 -0500, Jonathon McKitrick wrote:
>> >    if (0 == i) {
>> >        foo(i);
>> >        bar(i); }
>> 
>> Of course, the whole problem with this example is not the formating
>> style, but the unnecessary use of a variable. It should be changed to:
>> 
>> 	if (!i) {foo(0); bar(0);}
>
>Except that 'style' says we should not use '!' for tests, unless the
>variable is declared boolean.  Otherwise, compare with 0.

I wrote that half seriously, half toungue in cheek. But in K&R style
(!i) is perfectly acceptable. I use it. If I were writing code for
FreeBSD core, I would not use it because I would respect the requested
style. But in my own software, I take all the shortcuts I can.

As I said in another message, to me all data is just binary. Besides,
last I checked, there was no intrinsic boolean type in C anyway.

At any rate, I'd just code the whole thing something like this:

	mov	ecx, [esp+4]
	jecxz	.skip
	push	ecx
	call	foo
	call	bar
	pop	ecx
.skip:
	ret

Who needs variables when there are registers. And who needs to
push 0 twice. ;)

Cheers,
Adam

--- 
Whiz Kid Technomagic - brand name computers for less.
See http://www.whizkidtech.net/pcwarehouse/ for details.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3.0.6.32.20010123095930.00a14550>