• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: C again
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C again


  • Subject: Re: C again
  • From: Jens Bjerrehuus <email@hidden>
  • Date: Sun, 31 Aug 2003 09:46:47 +0200

sxndag 31. aug 2003 kl. 01:57 skrev David Thorp:

while (((ch = PEEK (myFile)) != EOF) && (error = 0))


The problem is error = 0 does not say is error equal to 0 but set
error to zero.

Oh Duh! Of course. Thanks.

You could get the compiler to help you see at least some of these kinds of errors. But, it would require you to stop using all those unneeded parentheses. :)

If you had written the expression like this:

while ((ch = getc (myFile)) != EOF && error = 0)

(which would be correct if the assignment was an equal-to instead) you would get an error like this:

klonk.c:9: invalid lvalue in assignment

I won't claim that this immediately points out the problem, but it at least would make you aware that there indeed is a problem here. Namely, the problem that && (and) has higher precedence than = (assignment). And, that the solution to that problem would be parentheses around the assignment (if you indeed wanted the assignment here) or to replace the assignment operator with the equal-to operator.

Kind regards
Jens
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: C again (From: David Thorp <email@hidden>)

  • Prev by Date: Re: Newbie question: forcing data format during saveDocumentTo:
  • Next by Date: Re: C
  • Previous by thread: Re: C again
  • Next by thread: Re: C again
  • Index(es):
    • Date
    • Thread