0

Excuse me for the title of this question, I will probably update the title once I have my answer.

I have this ancient code compiling and working with gcc 4.x:

struct S {
    int a;
    int b;
};

int main(void)
{
    return (struct S){1,2}.a;
}

As you can see I cast the {1,2} to struct S to access the member a. How is this feature called in the C language? Or what are the correct terms to apply for this construct?

Is this feature supported in any of the visual studio versions?

Patrick B.
  • 11,773
  • 8
  • 58
  • 101
  • 1
    It is like GCC [6.25 Compound Literals](http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html) – Grijesh Chauhan Oct 03 '13 at 15:59
  • 1
    I found this question, please help me close mine: http://stackoverflow.com/questions/3869963/compound-literals-in-msvc – Patrick B. Oct 03 '13 at 16:05
  • @Patrick B: My copy of MSVS 2012 Premium does *not* support it. I get `error C2059: syntax error: '{'`. I understand C99 *will* be supported in MSVS2013. You can download it for free and try it: [MSVS 2013 Express Preview](http://www.microsoft.com/en-us/download/details.aspx?id=39313). – paulsm4 Oct 03 '13 at 17:38

1 Answers1

3

It's called compound literal, which is introduced in C99. The relevant part in the standard is 6.5.2.5 Compound literals

The bad news is Visual Studio only supports C89 right now, so this feature is not supported in Visual Studio.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294