a bug of gcc, or a bug of mine?

This is a discussion on a bug of gcc, or a bug of mine? within the C Programming forums, part of the General Programming Boards category; Hi, all! The code below compiled by gcc and icc behaves differently. Could anyone help me to figure the problem? ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    20,968
    Yes, v is quite obviously an array of 2 ints.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 10:18 PM
  2. mine sweeper code help..
    By transgalactic2 in forum C Programming
    Replies: 9
    Last Post: 01-01-2009, 08: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, 02:19 PM
  4. Using other programs in mine
    By mramazing in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2006, 02:19 AM
  5. Another game of mine...
    By valar_king in forum Game Programming
    Replies: 7
    Last Post: 01-03-2002, 08:44 AM

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