• 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: Inside or outside an if statement - what's the difference?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inside or outside an if statement - what's the difference?


  • Subject: Re: Inside or outside an if statement - what's the difference?
  • From: Ian Jackson <email@hidden>
  • Date: Fri, 30 Sep 2005 07:05:08 +1200

Hi, Thanks for the clear response. Unfortunately, I should definitely have mentioned in the original post that I had already tried setting break points. The meetConditions part is deliberately set meetConditions = YES, just before the code is executed, and that's what appears to be the case in the debugger. A break point in the code that executes if the conditions are met (addParticularSegmentToPath) does stop the program, so the code is definitely being executed. It seems like, just being inside the if statement causes some sort of problem.

Ian.


On 30/09/2005, at 2:59 AM, James Bucanek wrote:

Ian Jackson wrote on Thursday, September 29, 2005:


It seems to suggest there's something
I'm totally not getting about what goes on with if statements.


There's nothing mysterous about an if statement. They are probably C's most basic construct.


You obviously have a bug in your program. Set a break point at the if statement. When your application stops at that point, examine the variable that make up 'meetConditions'. Use the Step command in the debugger. If the debugger moves into the block, then the conditional expression evaluated to true (non-zero). If it skips over the block, then your condition expression evaluated to false (zero). If you want to watch this happen, assign the expresstion to an intermediate variable so you can see the results of the conditional expression:

    in meetsCondition = ( ... your conditional statement ... )
    if (meetsCondition)
        {
        ...
        }

It sound like you're new to C, so I'll point out a number of pitfalls that catch newbie C programmers:

1) Make sure you didn't code an assigement (any C statement can be an assignement).

    if ( a == 1 )   // true iff a equals 1

if ( a = 1 ) // always true: 1 is assigned to a, and the result of the expr is always 1

    if ( a <= 1 )   // true iff a is less than or equal to 1

if ( a <<= 1 ) // a is shifted one bit to the left, true if a is non-zero

2) Every expression is an integer

if ( 0 < a < 5 ) // this is a valid C expression, but will always be true
// it evaluates to (0<a) < 5 that reduces in either 0<5 or 1<5


3) != is not =!

    if ( a =! b )       // this evaluates to a = (!b)

4) Understand the difference between bitwise and logical operators. & and && are not the same and have different orders of evaluation.

... and there are about a hundred more.

--
James Bucanek


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Inside or outside an if statement - what's the difference?
      • From: James Bucanek <email@hidden>
References: 
 >Re: Inside or outside an if statement - what's the difference? (From: James Bucanek <email@hidden>)

  • Prev by Date: Background if Login Item launched
  • Next by Date: Re: How to scroll a text view
  • Previous by thread: Re: Inside or outside an if statement - what's the difference?
  • Next by thread: Re: Inside or outside an if statement - what's the difference?
  • Index(es):
    • Date
    • Thread