Thread: a bug of gcc, or a bug of mine?

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    16

    a bug of gcc, or a bug of mine?

    Hi, all!

    The code below compiled by gcc and icc behaves differently. Could anyone help me to figure the problem?

    Code:
    #include <stdio.h>
    int main(void) {
      int v[2];
      int i;
      v[0] = 10;
      v[1] = 20;
      i = 0;
      if (v[i++] == v[i])
        printf("hello\n");
      return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    34,850
    Yes, your code is broken.
    Question 3.2
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    16
    Thank you!

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    13
    is v[] an array??

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    25,510
    Yes, v is quite obviously an array of 2 ints.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mine sweeper help..
    By transgalactic2 in forum C Programming
    Replies: 8
    Last Post: 01-04-2009, 11:18 PM
  2. mine sweeper code help..
    By transgalactic2 in forum C Programming
    Replies: 9
    Last Post: 01-01-2009, 09:44 AM
  3. a C++ library of mine.
    By jinhao in forum A Brief History of Cprogramming.com
    Replies: 72
    Last Post: 09-13-2008, 03:19 PM
  4. Using other programs in mine
    By mramazing in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2006, 03:19 AM
  5. Another game of mine...
    By valar_king in forum Game Programming
    Replies: 7
    Last Post: 01-03-2002, 09:44 AM
Website Security Test