Opened 16 months ago
#279 new defect
Compound Literal Construction Runs with Incorrect Timing
Reported by: | ajbeach | Owned by: | |
---|---|---|---|
Priority: | minor | Component: | cfa-cc |
Version: | 1.0 | Keywords: | |
Cc: |
Description
The construction of a compound literal is happens too early.
The following code works in both C and Cforall:
#include <stdio.h> struct iwrap { int value; }; int main(int argc, char** argv) { int i = 3; printf("before construction: %d\n", i); struct iwrap obj = (++i, (struct iwrap){i}); printf("during construction: %d\n", obj.value); printf("after construction: %d\n", i); }
C outputs:
before construction: 3 during construction: 4 after construction: 4
Cforall outputs:
before construction: 3 during construction: 3 after construction: 4
I believe the constructor is being run when the storage is being allocated and not when the expression is actually evaluated.
Note: See
TracTickets for help on using
tickets.