Removing "if (a = b)" warning

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen

    #31
    Re: Removing "if (a = b)" warning

    In article <43617937.7CED@ mindspring.com> , pete <pfiland@mindsp ring.com>
    writes[color=blue]
    >Martin Ambuhl wrote:[color=green]
    >>
    >> Stephen wrote:[color=darkred]
    >> > Is there a standard way to remove
    >> > the warning that a C compiler might
    >> > produce from the statement:
    >> >
    >> > if (a = b) {}
    >> >
    >> > I don't want to do:
    >> >
    >> > if ((a = b) != 0) {}[/color][/color][/color]
    [color=blue]
    > if (A)
    >means exactly the same thing as
    > if ((A) != 0)
    >
    >for any and all possible meanings of A, including funky macros.[/color]

    You've missed the point:

    if ((a = b) != 0)

    will kill the warning generated by:

    if (a = b)

    Comment

    • Peter Nilsson

      #32
      Re: Removing &quot;if (a = b)&quot; warning

      Ben Pfaff wrote:[color=blue]
      > pete <pfiland@mindsp ring.com> writes:[color=green]
      > > if (A)
      > > means exactly the same thing as
      > > if ((A) != 0)
      > >
      > > for any and all possible meanings of A, including funky macros.[/color]
      >
      > Here's an interesting funky macro to go along with that
      > observation:
      > #define if(expr) if ((expr) != 0)
      > (Does it break anything?)[/color]

      It can if you include a standard header after the macro
      definition. Also, if A is an expression that includes a non-
      parenthesised comma, then there is a problem since the macro
      only takes one parameter.

      --
      Peter

      Comment

      • pete

        #33
        Re: Removing &quot;if (a = b)&quot; warning

        Stephen wrote:[color=blue]
        >
        > In article <43617937.7CED@ mindspring.com> , pete <pfiland@mindsp ring.com>
        > writes[color=green]
        > >Martin Ambuhl wrote:[color=darkred]
        > >>
        > >> Stephen wrote:
        > >> > Is there a standard way to remove
        > >> > the warning that a C compiler might
        > >> > produce from the statement:
        > >> >
        > >> > if (a = b) {}
        > >> >
        > >> > I don't want to do:
        > >> >
        > >> > if ((a = b) != 0) {}[/color][/color]
        >[color=green]
        > > if (A)
        > >means exactly the same thing as
        > > if ((A) != 0)
        > >
        > >for any and all possible meanings of A, including funky macros.[/color]
        >
        > You've missed the point:[/color]

        That happens more often than I like.
        [color=blue]
        > if ((a = b) != 0)
        >
        > will kill the warning generated by:
        >
        > if (a = b)[/color]

        I thought that you wanted to kill the warning.

        if ((a = b) != 0) {}
        kills the warning very nicely
        without changing the meaning of the code.

        --
        pete

        Comment

        Working...