The program below, which is a slight variation of a program from C99
section 6.5.3.4, contains an execution-time sizeof operator and its
argument should thus be evaluated.  Nevertheless, "i" in not incremented.

I would expect "i=1" to be printed.  I get "i=0".

(Sun's C compiler seems to do the same thing.)



#include <stdio.h>

size_t fsize3 (int n)
{
  int i = 0;
  char b[1][n+3];       // Variable length array.
  size_t s = sizeof (b[i++]);    // Execution time sizeof.
  printf ("i=%d\n", i);
  return s;
}

int main()
{
  size_t size;
  size = fsize3(10);
  return 0;
}

-- 
           Summary: Execution-time sizeof drops side effects
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: terra at gnome dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparc-sun-solaris2.8
  GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sparc-sun-solaris2.8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18740

Reply via email to