CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Syntax question

  1. #1
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Syntax question

    I'm really astonished and cannot figure it out ...

    Code:
    bool Mybool[10][5];
    int x,i;
    
    ...
    if (!Mybool[x],i) { ... }
    My intention was obviously to write !Mybool[x][i] but the compiler didn't detect any error ... and I spent a lot of time until I found the mistake.

    My question ... what is the compiler doing with this incorrect syntax?

    Thks
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  2. #2
    Join Date
    May 2007
    Posts
    437

    Re: Syntax question

    so whats an issue ??
    ashu
    always use code tag

  3. #3
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: Syntax question

    well ... I would like to understand/know what is being compiled when an

    if (expresion1,expresion2)

    is written.

    Just "to know" if you like it that way.
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  4. #4
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Syntax question

    Expression 1 is evaluated, then expression 2. The result of expression 2 is used by the 'if' to determine program flow.

    Your original code is equivalent to...

    Code:
    !Mybool[x];
    
    if (i) { ... }
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  5. #5
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Syntax question

    Quote Originally Posted by DeepButi View Post
    I'm really astonished and cannot figure it out ...

    Code:
    bool Mybool[10][5];
    int x,i;
    
    ...
    if (!Mybool[x],i) { ... }
    My intention was obviously to write !Mybool[x][i] but the compiler didn't detect any error ... and I spent a lot of time until I found the mistake.

    My question ... what is the compiler doing with this incorrect syntax?

    Thks
    You've stumbled onto the ',' operator. That's why there was no compile error.

    Viggy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured