Re: need help..



Nils Weller wrote:
> CBFalconer wrote:
>
.... snip ...
>>
>> Which you can easily avoid at all times by simply cultivating the
>> habit of writing:
>>
>> if (2 == line) ...
>>
>> i.e. put the constant first.
>
> I don't like this habit for various reasons:
>
> 1) Though the reversed version is semantically equivalent, it is harder
> to read unless you are already quite used to reversing the test. The
> vast majority of programmers always puts the variable they want to test
> first, i.e. they write
>
> if (foo == 0) {
>
> The few who write
>
> if (0 == foo) {
>
.... snip ...
>
> 3) Quality compilers warn about the ``if (foo = 0)'' construct. I know
> for a fact only that gcc and HP's compilers do this (and not because the
> bug ever occured to me, but because I explictly tested these compilers),
> but it is very likely that the offerings of vendors such as Comeau,
> Compaq, Intel, SGI, IBM, Sun and a host of others are also capable of
> doing this (I don't have these compilers handy right now and will let
> others fill in the blanks.)

And I dislike that warning. I often want to write something like:

if (!(p = malloc(sizeof *p))) getoutahere("no memory");
else if (!(p->ptr = malloc(sizeof *p->ptr))) {
free(p); getoutahere("no memory");
}
else {
/* all seems well, go for it */
}
/* Unless getoutahere does something, we always get here */

and similar things to do with opening files, getting parameters,
etc.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


.



Relevant Pages

  • Re: VECTOR data types and intrinsic functions
    ... and compilers have been able to generate code for it ... from standard f77 onwards. ... a preprocessor could convert the VECTOR style to a more ...
    (comp.lang.fortran)
  • Re: Why do you like C more than other programming languages?
    ... non-portability into their code by using C99 features. ... implementors can't even be bothered to implement C90 properly... ... If C99 compilers were readily available (and implemented at least ...
    (comp.lang.c)
  • Re: ARM7, DSP and mobile phone, how and why?
    ... > is portable across many compilers and architectures with little effort. ... magnitude machines. ... rely on the results of signed shift. ...
    (comp.lang.c)
  • Re: atheists for freedom
    ... [quoting Nando I even mark my snip] ... the habit to think in terms of cause and effect only, ... atheist there is a tendency to avoid anything spiritual. ...
    (talk.origins)
  • Re: Regular as clockw*rk ...
    ... It's become a habit, one I really must ... get out of somehow. ... How do other people cope? ...
    (uk.people.silversurfers)