Like Tree1Likes
  • 1 Post By Matticus

DDD conditional breakpoint : expression error

This is a discussion on DDD conditional breakpoint : expression error within the C Programming forums, part of the General Programming Boards category; I've just read te book The art of debugging with GDB, DDD and Eclipse, but I just can't find out ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    44

    DDD conditional breakpoint : expression error

    I've just read te book The art of debugging with GDB, DDD and Eclipse, but I just can't find out what I'm doing wrong:

    I'm using DDD i've set a breakpoint at the first for loop. Then I fill in at the properties of the breakpoint the expression : won if i==2 and click apply
    I just get a message : junk at the end of expression

    Code:
    bool
    won(void)
    {
        int prevpos = 0;
        int count = 0;
    
        for (i = 0 ; i <= d -1 ; i++)
        {
            for (j = 0 ; j <= d -1; j++)
            {
                prevpos = board[i][j];
                if(board[i][j] < prevpos )
                    count++;
                    if (count == (d*d)-1)
                    return true;
            }
    
        }
        return false;
    }
    hopefully someone can shed a light on this.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by lamko View Post
    I've just read te book The art of debugging with GDB, DDD and Eclipse, but I just can't find out what I'm doing wrong:

    I'm using DDD i've set a breakpoint at the first for loop. Then I fill in at the properties of the breakpoint the expression : won if i==2 and click apply
    I just get a message : junk at the end of expression

    Code:
    bool
    won(void)
    {
        int prevpos = 0;
        int count = 0;
    
        for (i = 0 ; i <= d -1 ; i++)
        {
            for (j = 0 ; j <= d -1; j++)
            {
                prevpos = board[i][j];
                if(board[i][j] < prevpos )
                    count++;
                    if (count == (d*d)-1)
                    return true;
            }
    
        }
        return false;
    }
    hopefully someone can shed a light on this.
    Don't know about DDD but your loops could use some work...

    for (i = 0; i <= d - 1; i++) is much simpler like this.... for (i = 0; i < d; i++) .... the behaviour is exactly the same.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Never used DDD, but: are you actually typing "won if i==2" in the box? If you want a conditional breakpoint, a quick glance at the manual suggests you should just use "i==2". If you are trying to do something else, maybe be a bit more specific about what you're trying to achieve.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    2,197
    To build on CommonTater's suggestion for loop improvement ... is this what you actually intended? Because this will never be true.

    Code:
        prevpos = board[i][j];
        if(board[i][j] < prevpos )
            ...
    CommonTater likes this.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Matticus View Post
    To build on CommonTater's suggestion for loop improvement ... is this what you actually intended? Because this will never be true.

    Code:
        prevpos = board[i][j];
        if(board[i][j] < prevpos )
            ...
    Nice catch! I looked right at that and missed it...

  6. #6
    Registered User
    Join Date
    Jul 2011
    Posts
    44
    d is a argument to the program which sets the dimension of the fifteen game.
    The function isn't working yet, so i'll think and you guys confirmed my error but thats why I want to use gdb. I'm not so much of a coder but after some debugging I'll get the stuff right. Just need some more experience.

    About the expression
    I've tried it and isnt working. I just want to get the outher loop to the third run : i=2 if tried different syntax. I'll test in DDD but I want to use it in codeblocks.
    You mean this manual ?
    GDB Internals
    Last edited by lamko; 07-28-2011 at 02:35 PM.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Quote Originally Posted by lamko View Post
    I've just read te book The art of debugging with GDB, DDD and Eclipse, but I just can't find out what I'm doing wrong:

    I'm using DDD i've set a breakpoint at the first for loop. Then I fill in at the properties of the breakpoint the expression : won if i==2 and click apply
    I just get a message : junk at the end of expression
    That DDD is just a GUI front-end to gdb, and what you are trying to do is known as setting a watchpoint in gdb.
    To do that in gdb, set breakpoint on won(), step into it, and set breakpoint at the line no. in won() when i == 2.
    Code:
    (gdb) b won          /* put a breakpoint on won() */
    (gdb) r              /* run the program */
    (gdb) b 7 if i=="3"  /* set breakpoint at line no 7 of won() when i == 3 */
    Last edited by itCbitC; 07-28-2011 at 02:39 PM.

  8. #8
    Registered User
    Join Date
    Jul 2011
    Posts
    44
    I've tried what you recommended but :
    The breakpoint just start at position zero with value zero. What I want to do is just simply put, go for example i=3 and j=2 then I want to read the value from the array. After that I want to go a couple of line further to get i =3 and j =3 and I want to get that value. So to put it really clear I donīt want to next next the whole array just to get at the good position.

    If I step into the function all values return to zero. If I'll stay in main it's working just as expected maybe I'm running at some technical limitations anyone a good book or link on this matter.
    Last edited by lamko; 07-28-2011 at 03:18 PM.

  9. #9
    Registered User
    Join Date
    Jun 2011
    Posts
    2,197
    Quote Originally Posted by CommonTater View Post
    Nice catch! I looked right at that and missed it...
    Thanks! Someone on this board (I think it was laserlight) recently mentioned how it's easier to write code than to read code. My short time on this board has shown that this is largely true.

  10. #10
    Registered User
    Join Date
    Jul 2011
    Posts
    44
    With a breakpoint on the beginning of the loop and one on the end + continue 15x i'll get exactly at the right position !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: expected an expression
    By cdmstr in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2011, 01:00 PM
  2. Replies: 2
    Last Post: 11-25-2009, 06:38 AM
  3. "C4127: conditional expression is constant" Huh?
    By cpjust in forum C++ Programming
    Replies: 27
    Last Post: 03-13-2008, 04:58 PM
  4. Expression syntax error
    By aama100 in forum C++ Programming
    Replies: 5
    Last Post: 02-04-2008, 06:55 PM
  5. expression error?
    By trekker in forum C++ Programming
    Replies: 3
    Last Post: 11-30-2003, 06:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21