| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: Pointers |
From: jcoffin{at}taeus.com
To: c_echo{at}yahoogroups.com
At 08:35 AM 9/11/2003 +0100, you wrote:
[ ... ]
>No, I don't think so. function() may return any non-zero value to be true.
> If it returned 2, your if would fail.
>
>Much better is:
>
>i = function(parm);
>if (i) /* ... */
IMO, this is only marginally better. The right way is like:
if ( i=function(parm))
>I don't see what the fascination is with cramming everything into a single
>statement. C just isn't built properly for that.
Simple: by getting into the habit of putting them together, you don't
accidentally do one part without the other. Just for example, if you write:
x = malloc(somesize);
it's easy to forget to add the:
if ( x == NULL)
// allocation failed.
OTOH, if you always write it as:
if ( NULL == (x=malloc(somesize)))
// allocation failed
you're much less likely to forget.
>Perl, however, ... ;-)
I suppose you have a point there: in C it's a question of whether you're
more interested in being certain your code is always correct (favors
merging the expressions) or readable (favors splitting them up).
In Perl, you might as well merge the expressions, since there's no chance
of it being readable anyway!
Later,
Jerry.
--- SoupGate-Win32 v1.05
* Origin: jcoffin{at}taeus.com (2:292/516.666)SEEN-BY: 633/267 270 @PATH: 292/516 854 140/1 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.