Compound literals in MSVC










8















In GCC, I'm able to do this:



(CachedPath)ino
inode->data = (struct Data)DATA_INIT;


where:



struct CachedPath

Ino ino;
;

typedef int8_t Depth;
struct Data

Offset size;
Blkno root;
Depth depth;
;
#define DATA_INIT 0, -1, 0


MSVC gives the following error for these kind of casts:



error C2143: syntax error : missing ';' before '{'


How can I do this in MSVC? Further note that the code has been converted from C99, where I used designated initializers for this, and then cast it similarly. Any clarity on how these various features relate between C99, and MSVC/GCC implementations of C++ is appreciated.










share|improve this question



















  • 2





    You might consider changing the title. Compound literals are not a cast operator. The set of types which are valid in a cast and the set which are valid for compound literals are completely disjoint, and the C standard makes a point of this.

    – R..
    Oct 6 '10 at 6:46















8















In GCC, I'm able to do this:



(CachedPath)ino
inode->data = (struct Data)DATA_INIT;


where:



struct CachedPath

Ino ino;
;

typedef int8_t Depth;
struct Data

Offset size;
Blkno root;
Depth depth;
;
#define DATA_INIT 0, -1, 0


MSVC gives the following error for these kind of casts:



error C2143: syntax error : missing ';' before '{'


How can I do this in MSVC? Further note that the code has been converted from C99, where I used designated initializers for this, and then cast it similarly. Any clarity on how these various features relate between C99, and MSVC/GCC implementations of C++ is appreciated.










share|improve this question



















  • 2





    You might consider changing the title. Compound literals are not a cast operator. The set of types which are valid in a cast and the set which are valid for compound literals are completely disjoint, and the C standard makes a point of this.

    – R..
    Oct 6 '10 at 6:46













8












8








8


2






In GCC, I'm able to do this:



(CachedPath)ino
inode->data = (struct Data)DATA_INIT;


where:



struct CachedPath

Ino ino;
;

typedef int8_t Depth;
struct Data

Offset size;
Blkno root;
Depth depth;
;
#define DATA_INIT 0, -1, 0


MSVC gives the following error for these kind of casts:



error C2143: syntax error : missing ';' before '{'


How can I do this in MSVC? Further note that the code has been converted from C99, where I used designated initializers for this, and then cast it similarly. Any clarity on how these various features relate between C99, and MSVC/GCC implementations of C++ is appreciated.










share|improve this question
















In GCC, I'm able to do this:



(CachedPath)ino
inode->data = (struct Data)DATA_INIT;


where:



struct CachedPath

Ino ino;
;

typedef int8_t Depth;
struct Data

Offset size;
Blkno root;
Depth depth;
;
#define DATA_INIT 0, -1, 0


MSVC gives the following error for these kind of casts:



error C2143: syntax error : missing ';' before '{'


How can I do this in MSVC? Further note that the code has been converted from C99, where I used designated initializers for this, and then cast it similarly. Any clarity on how these various features relate between C99, and MSVC/GCC implementations of C++ is appreciated.







c++ c visual-studio-2010 gcc struct






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 6 '10 at 7:10







Matt Joiner

















asked Oct 6 '10 at 6:24









Matt JoinerMatt Joiner

56.6k77292462




56.6k77292462







  • 2





    You might consider changing the title. Compound literals are not a cast operator. The set of types which are valid in a cast and the set which are valid for compound literals are completely disjoint, and the C standard makes a point of this.

    – R..
    Oct 6 '10 at 6:46












  • 2





    You might consider changing the title. Compound literals are not a cast operator. The set of types which are valid in a cast and the set which are valid for compound literals are completely disjoint, and the C standard makes a point of this.

    – R..
    Oct 6 '10 at 6:46







2




2





You might consider changing the title. Compound literals are not a cast operator. The set of types which are valid in a cast and the set which are valid for compound literals are completely disjoint, and the C standard makes a point of this.

– R..
Oct 6 '10 at 6:46





You might consider changing the title. Compound literals are not a cast operator. The set of types which are valid in a cast and the set which are valid for compound literals are completely disjoint, and the C standard makes a point of this.

– R..
Oct 6 '10 at 6:46












4 Answers
4






active

oldest

votes


















12














The construct (Type)initialisers is not a cast operation, but it is the syntactic construct of a compound literal.
This is a C99 construct, which GCC also supports in its C++ compiler as an extension. As far as I can determine, compound literals are not supported by MSVC in either its C or C++ mode.



The alternatives for this construct are



  • Explicitly declare and initialise a temporary object of the desired struct type and use that instead of the compound literal in the assignment

  • Instead of doing a single assignment with the compound literal, use a separate assignment for each individual member.





share|improve this answer























  • +1 better-written than my answer

    – R..
    Oct 6 '10 at 7:25






  • 1





    Is this still valid newer MSVC versions? (answer is now quite old)

    – ideasman42
    Nov 28 '17 at 10:27


















4














MSVC is not conformant to C99 and only loosely conformant to previous versions of the C standard. I know no way to do what you want syntactically with MSVC, but the same effect can be obtained by using static const structs instead of anonymous compound literal constants, and local struct variables that are initialized with the correct values instead of anonymous compound literals that are nonconstant.



The idea behind this approach is that a C99 compound literal is (at least nearly) equivalent to a local variable of the same type at the same scope, initialized with the contents of the braces. Using static const structs in the case where the data is constant is just an optimization (it will likely produce smaller/faster code than the C99 compound literal approach).






share|improve this answer




















  • 1





    MSVC is very precisely conformant to C89/90 standard. What is the strange claim of being "loosely conformant" based upon?

    – AnT
    Oct 6 '10 at 6:49






  • 2





    Most of the conformance problems I know about are the standard library and related to internationalization amendments ("C95" I think it's typically called). For instance, incorrect behavior of the %s and %ls format specifiers in wprintf and printf, respectively, and the use of multi-wchar_t characters (UTF-16) in ways that breaks the C multibyte/wide conversion API. I suspect the compiler/compilation environment itself has some bugs too though - like keyword/function/type names that conflict with those reserved for the application.

    – R..
    Oct 6 '10 at 6:59











  • What do you mean by "use static const structs"?

    – Matt Joiner
    Oct 6 '10 at 7:12











  • Along with #define DATA_INIT 0, -1, 0, use static const struct Data data_init = DATA_INIT;, and then use the latter for assignments and the former for initializations.

    – R..
    Oct 6 '10 at 7:24











  • Very nice, I hoped as much.

    – Matt Joiner
    Oct 7 '10 at 0:57


















1














MSVC is a mix of standards, and is not fully compliant with most of them, thus, you'll probably need to use a default initializer/constructor, like so (C++ way):



#define DATA_INIT 0,-1,0
inode->data = Data(DATA_INIT);

struct Data

Offset size;
Blkno root;
Depth depth;

Data(Offset size, Blkno root, Depth depth) : size(size), root(root), depth(depth)


;





share|improve this answer




















  • 1





    This is not remotely C code.

    – R..
    Oct 6 '10 at 6:40











  • @R.. please read the tags and the OP's post, this is C++ code, like the OP requested

    – Necrolis
    Oct 6 '10 at 6:42












  • OK, reverted the -1. Sorry.

    – R..
    Oct 6 '10 at 6:43






  • 1





    You've forgot to define a constructor accepting 3 parameters for struct Data.

    – atzz
    Oct 6 '10 at 6:59











  • @atzz: good catch, I'll add that, though I remember that MSVC could auto initialize without one, can't test that at the moment though

    – Necrolis
    Oct 6 '10 at 7:11


















0














Visual Studio, since VS2013, supports Compound literals and Designated initializers.
Which C99 features are available in the MS Visual Studio compiler?



Example:



// main.c
#include <stdio.h>

void func(int(*array)[3]);

int main()

// Designated initializers

int a[6] = [4] = 29, [2] = 15 ; // [0, 0, 15, 0, 29, 0]

struct point int x, y; ;
struct point p = .y = 13, .x = 27 ; // x = 27, y = 13

union foo int i; double d; ;
union foo f = .d = 4 ; // d = 4.0

struct point ptarray[5] = [2].y = 34, [2].x = 42, [0].x = 58 ;
// (58 0), (0 0), (42 34), (0 0), (0 0)

// Compound literals

int *a1 = NULL;
a1 = (int[6]) [4] = 29, [2] = 15 ; // [0, 0, 15, 0, 29, 0]

struct point p1;
p1 = (struct point) .y = 13, .x = 27 ; // x = 27, y = 13

union foo f1;
f1 = (union foo) .d = 4 ; // d = 4.0

struct point *ptarray1 = NULL;
ptarray1 = (struct point[5]) [2].y = 34, [2].x = 42, [0].x = 58 ;
// (58 0), (0 0), (42 34), (0 0), (0 0)

int *p2 = NULL;
p2 = (int[2]) -1 ;
p2 = (int) -73, 89, 92 ;
func(&(int) -73, 89, 92 );

return 0;


void func(int(*array)[3])

for (int i = 0; i < 3; i++)
printf("%d ", (*array)[i]);







share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3869963%2fcompound-literals-in-msvc%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    12














    The construct (Type)initialisers is not a cast operation, but it is the syntactic construct of a compound literal.
    This is a C99 construct, which GCC also supports in its C++ compiler as an extension. As far as I can determine, compound literals are not supported by MSVC in either its C or C++ mode.



    The alternatives for this construct are



    • Explicitly declare and initialise a temporary object of the desired struct type and use that instead of the compound literal in the assignment

    • Instead of doing a single assignment with the compound literal, use a separate assignment for each individual member.





    share|improve this answer























    • +1 better-written than my answer

      – R..
      Oct 6 '10 at 7:25






    • 1





      Is this still valid newer MSVC versions? (answer is now quite old)

      – ideasman42
      Nov 28 '17 at 10:27















    12














    The construct (Type)initialisers is not a cast operation, but it is the syntactic construct of a compound literal.
    This is a C99 construct, which GCC also supports in its C++ compiler as an extension. As far as I can determine, compound literals are not supported by MSVC in either its C or C++ mode.



    The alternatives for this construct are



    • Explicitly declare and initialise a temporary object of the desired struct type and use that instead of the compound literal in the assignment

    • Instead of doing a single assignment with the compound literal, use a separate assignment for each individual member.





    share|improve this answer























    • +1 better-written than my answer

      – R..
      Oct 6 '10 at 7:25






    • 1





      Is this still valid newer MSVC versions? (answer is now quite old)

      – ideasman42
      Nov 28 '17 at 10:27













    12












    12








    12







    The construct (Type)initialisers is not a cast operation, but it is the syntactic construct of a compound literal.
    This is a C99 construct, which GCC also supports in its C++ compiler as an extension. As far as I can determine, compound literals are not supported by MSVC in either its C or C++ mode.



    The alternatives for this construct are



    • Explicitly declare and initialise a temporary object of the desired struct type and use that instead of the compound literal in the assignment

    • Instead of doing a single assignment with the compound literal, use a separate assignment for each individual member.





    share|improve this answer













    The construct (Type)initialisers is not a cast operation, but it is the syntactic construct of a compound literal.
    This is a C99 construct, which GCC also supports in its C++ compiler as an extension. As far as I can determine, compound literals are not supported by MSVC in either its C or C++ mode.



    The alternatives for this construct are



    • Explicitly declare and initialise a temporary object of the desired struct type and use that instead of the compound literal in the assignment

    • Instead of doing a single assignment with the compound literal, use a separate assignment for each individual member.






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 6 '10 at 7:04









    Bart van Ingen SchenauBart van Ingen Schenau

    13k22435




    13k22435












    • +1 better-written than my answer

      – R..
      Oct 6 '10 at 7:25






    • 1





      Is this still valid newer MSVC versions? (answer is now quite old)

      – ideasman42
      Nov 28 '17 at 10:27

















    • +1 better-written than my answer

      – R..
      Oct 6 '10 at 7:25






    • 1





      Is this still valid newer MSVC versions? (answer is now quite old)

      – ideasman42
      Nov 28 '17 at 10:27
















    +1 better-written than my answer

    – R..
    Oct 6 '10 at 7:25





    +1 better-written than my answer

    – R..
    Oct 6 '10 at 7:25




    1




    1





    Is this still valid newer MSVC versions? (answer is now quite old)

    – ideasman42
    Nov 28 '17 at 10:27





    Is this still valid newer MSVC versions? (answer is now quite old)

    – ideasman42
    Nov 28 '17 at 10:27













    4














    MSVC is not conformant to C99 and only loosely conformant to previous versions of the C standard. I know no way to do what you want syntactically with MSVC, but the same effect can be obtained by using static const structs instead of anonymous compound literal constants, and local struct variables that are initialized with the correct values instead of anonymous compound literals that are nonconstant.



    The idea behind this approach is that a C99 compound literal is (at least nearly) equivalent to a local variable of the same type at the same scope, initialized with the contents of the braces. Using static const structs in the case where the data is constant is just an optimization (it will likely produce smaller/faster code than the C99 compound literal approach).






    share|improve this answer




















    • 1





      MSVC is very precisely conformant to C89/90 standard. What is the strange claim of being "loosely conformant" based upon?

      – AnT
      Oct 6 '10 at 6:49






    • 2





      Most of the conformance problems I know about are the standard library and related to internationalization amendments ("C95" I think it's typically called). For instance, incorrect behavior of the %s and %ls format specifiers in wprintf and printf, respectively, and the use of multi-wchar_t characters (UTF-16) in ways that breaks the C multibyte/wide conversion API. I suspect the compiler/compilation environment itself has some bugs too though - like keyword/function/type names that conflict with those reserved for the application.

      – R..
      Oct 6 '10 at 6:59











    • What do you mean by "use static const structs"?

      – Matt Joiner
      Oct 6 '10 at 7:12











    • Along with #define DATA_INIT 0, -1, 0, use static const struct Data data_init = DATA_INIT;, and then use the latter for assignments and the former for initializations.

      – R..
      Oct 6 '10 at 7:24











    • Very nice, I hoped as much.

      – Matt Joiner
      Oct 7 '10 at 0:57















    4














    MSVC is not conformant to C99 and only loosely conformant to previous versions of the C standard. I know no way to do what you want syntactically with MSVC, but the same effect can be obtained by using static const structs instead of anonymous compound literal constants, and local struct variables that are initialized with the correct values instead of anonymous compound literals that are nonconstant.



    The idea behind this approach is that a C99 compound literal is (at least nearly) equivalent to a local variable of the same type at the same scope, initialized with the contents of the braces. Using static const structs in the case where the data is constant is just an optimization (it will likely produce smaller/faster code than the C99 compound literal approach).






    share|improve this answer




















    • 1





      MSVC is very precisely conformant to C89/90 standard. What is the strange claim of being "loosely conformant" based upon?

      – AnT
      Oct 6 '10 at 6:49






    • 2





      Most of the conformance problems I know about are the standard library and related to internationalization amendments ("C95" I think it's typically called). For instance, incorrect behavior of the %s and %ls format specifiers in wprintf and printf, respectively, and the use of multi-wchar_t characters (UTF-16) in ways that breaks the C multibyte/wide conversion API. I suspect the compiler/compilation environment itself has some bugs too though - like keyword/function/type names that conflict with those reserved for the application.

      – R..
      Oct 6 '10 at 6:59











    • What do you mean by "use static const structs"?

      – Matt Joiner
      Oct 6 '10 at 7:12











    • Along with #define DATA_INIT 0, -1, 0, use static const struct Data data_init = DATA_INIT;, and then use the latter for assignments and the former for initializations.

      – R..
      Oct 6 '10 at 7:24











    • Very nice, I hoped as much.

      – Matt Joiner
      Oct 7 '10 at 0:57













    4












    4








    4







    MSVC is not conformant to C99 and only loosely conformant to previous versions of the C standard. I know no way to do what you want syntactically with MSVC, but the same effect can be obtained by using static const structs instead of anonymous compound literal constants, and local struct variables that are initialized with the correct values instead of anonymous compound literals that are nonconstant.



    The idea behind this approach is that a C99 compound literal is (at least nearly) equivalent to a local variable of the same type at the same scope, initialized with the contents of the braces. Using static const structs in the case where the data is constant is just an optimization (it will likely produce smaller/faster code than the C99 compound literal approach).






    share|improve this answer















    MSVC is not conformant to C99 and only loosely conformant to previous versions of the C standard. I know no way to do what you want syntactically with MSVC, but the same effect can be obtained by using static const structs instead of anonymous compound literal constants, and local struct variables that are initialized with the correct values instead of anonymous compound literals that are nonconstant.



    The idea behind this approach is that a C99 compound literal is (at least nearly) equivalent to a local variable of the same type at the same scope, initialized with the contents of the braces. Using static const structs in the case where the data is constant is just an optimization (it will likely produce smaller/faster code than the C99 compound literal approach).







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Oct 6 '10 at 6:43

























    answered Oct 6 '10 at 6:31









    R..R..

    158k26263564




    158k26263564







    • 1





      MSVC is very precisely conformant to C89/90 standard. What is the strange claim of being "loosely conformant" based upon?

      – AnT
      Oct 6 '10 at 6:49






    • 2





      Most of the conformance problems I know about are the standard library and related to internationalization amendments ("C95" I think it's typically called). For instance, incorrect behavior of the %s and %ls format specifiers in wprintf and printf, respectively, and the use of multi-wchar_t characters (UTF-16) in ways that breaks the C multibyte/wide conversion API. I suspect the compiler/compilation environment itself has some bugs too though - like keyword/function/type names that conflict with those reserved for the application.

      – R..
      Oct 6 '10 at 6:59











    • What do you mean by "use static const structs"?

      – Matt Joiner
      Oct 6 '10 at 7:12











    • Along with #define DATA_INIT 0, -1, 0, use static const struct Data data_init = DATA_INIT;, and then use the latter for assignments and the former for initializations.

      – R..
      Oct 6 '10 at 7:24











    • Very nice, I hoped as much.

      – Matt Joiner
      Oct 7 '10 at 0:57












    • 1





      MSVC is very precisely conformant to C89/90 standard. What is the strange claim of being "loosely conformant" based upon?

      – AnT
      Oct 6 '10 at 6:49






    • 2





      Most of the conformance problems I know about are the standard library and related to internationalization amendments ("C95" I think it's typically called). For instance, incorrect behavior of the %s and %ls format specifiers in wprintf and printf, respectively, and the use of multi-wchar_t characters (UTF-16) in ways that breaks the C multibyte/wide conversion API. I suspect the compiler/compilation environment itself has some bugs too though - like keyword/function/type names that conflict with those reserved for the application.

      – R..
      Oct 6 '10 at 6:59











    • What do you mean by "use static const structs"?

      – Matt Joiner
      Oct 6 '10 at 7:12











    • Along with #define DATA_INIT 0, -1, 0, use static const struct Data data_init = DATA_INIT;, and then use the latter for assignments and the former for initializations.

      – R..
      Oct 6 '10 at 7:24











    • Very nice, I hoped as much.

      – Matt Joiner
      Oct 7 '10 at 0:57







    1




    1





    MSVC is very precisely conformant to C89/90 standard. What is the strange claim of being "loosely conformant" based upon?

    – AnT
    Oct 6 '10 at 6:49





    MSVC is very precisely conformant to C89/90 standard. What is the strange claim of being "loosely conformant" based upon?

    – AnT
    Oct 6 '10 at 6:49




    2




    2





    Most of the conformance problems I know about are the standard library and related to internationalization amendments ("C95" I think it's typically called). For instance, incorrect behavior of the %s and %ls format specifiers in wprintf and printf, respectively, and the use of multi-wchar_t characters (UTF-16) in ways that breaks the C multibyte/wide conversion API. I suspect the compiler/compilation environment itself has some bugs too though - like keyword/function/type names that conflict with those reserved for the application.

    – R..
    Oct 6 '10 at 6:59





    Most of the conformance problems I know about are the standard library and related to internationalization amendments ("C95" I think it's typically called). For instance, incorrect behavior of the %s and %ls format specifiers in wprintf and printf, respectively, and the use of multi-wchar_t characters (UTF-16) in ways that breaks the C multibyte/wide conversion API. I suspect the compiler/compilation environment itself has some bugs too though - like keyword/function/type names that conflict with those reserved for the application.

    – R..
    Oct 6 '10 at 6:59













    What do you mean by "use static const structs"?

    – Matt Joiner
    Oct 6 '10 at 7:12





    What do you mean by "use static const structs"?

    – Matt Joiner
    Oct 6 '10 at 7:12













    Along with #define DATA_INIT 0, -1, 0, use static const struct Data data_init = DATA_INIT;, and then use the latter for assignments and the former for initializations.

    – R..
    Oct 6 '10 at 7:24





    Along with #define DATA_INIT 0, -1, 0, use static const struct Data data_init = DATA_INIT;, and then use the latter for assignments and the former for initializations.

    – R..
    Oct 6 '10 at 7:24













    Very nice, I hoped as much.

    – Matt Joiner
    Oct 7 '10 at 0:57





    Very nice, I hoped as much.

    – Matt Joiner
    Oct 7 '10 at 0:57











    1














    MSVC is a mix of standards, and is not fully compliant with most of them, thus, you'll probably need to use a default initializer/constructor, like so (C++ way):



    #define DATA_INIT 0,-1,0
    inode->data = Data(DATA_INIT);

    struct Data

    Offset size;
    Blkno root;
    Depth depth;

    Data(Offset size, Blkno root, Depth depth) : size(size), root(root), depth(depth)


    ;





    share|improve this answer




















    • 1





      This is not remotely C code.

      – R..
      Oct 6 '10 at 6:40











    • @R.. please read the tags and the OP's post, this is C++ code, like the OP requested

      – Necrolis
      Oct 6 '10 at 6:42












    • OK, reverted the -1. Sorry.

      – R..
      Oct 6 '10 at 6:43






    • 1





      You've forgot to define a constructor accepting 3 parameters for struct Data.

      – atzz
      Oct 6 '10 at 6:59











    • @atzz: good catch, I'll add that, though I remember that MSVC could auto initialize without one, can't test that at the moment though

      – Necrolis
      Oct 6 '10 at 7:11















    1














    MSVC is a mix of standards, and is not fully compliant with most of them, thus, you'll probably need to use a default initializer/constructor, like so (C++ way):



    #define DATA_INIT 0,-1,0
    inode->data = Data(DATA_INIT);

    struct Data

    Offset size;
    Blkno root;
    Depth depth;

    Data(Offset size, Blkno root, Depth depth) : size(size), root(root), depth(depth)


    ;





    share|improve this answer




















    • 1





      This is not remotely C code.

      – R..
      Oct 6 '10 at 6:40











    • @R.. please read the tags and the OP's post, this is C++ code, like the OP requested

      – Necrolis
      Oct 6 '10 at 6:42












    • OK, reverted the -1. Sorry.

      – R..
      Oct 6 '10 at 6:43






    • 1





      You've forgot to define a constructor accepting 3 parameters for struct Data.

      – atzz
      Oct 6 '10 at 6:59











    • @atzz: good catch, I'll add that, though I remember that MSVC could auto initialize without one, can't test that at the moment though

      – Necrolis
      Oct 6 '10 at 7:11













    1












    1








    1







    MSVC is a mix of standards, and is not fully compliant with most of them, thus, you'll probably need to use a default initializer/constructor, like so (C++ way):



    #define DATA_INIT 0,-1,0
    inode->data = Data(DATA_INIT);

    struct Data

    Offset size;
    Blkno root;
    Depth depth;

    Data(Offset size, Blkno root, Depth depth) : size(size), root(root), depth(depth)


    ;





    share|improve this answer















    MSVC is a mix of standards, and is not fully compliant with most of them, thus, you'll probably need to use a default initializer/constructor, like so (C++ way):



    #define DATA_INIT 0,-1,0
    inode->data = Data(DATA_INIT);

    struct Data

    Offset size;
    Blkno root;
    Depth depth;

    Data(Offset size, Blkno root, Depth depth) : size(size), root(root), depth(depth)


    ;






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Oct 6 '10 at 7:13

























    answered Oct 6 '10 at 6:35









    NecrolisNecrolis

    22.3k24895




    22.3k24895







    • 1





      This is not remotely C code.

      – R..
      Oct 6 '10 at 6:40











    • @R.. please read the tags and the OP's post, this is C++ code, like the OP requested

      – Necrolis
      Oct 6 '10 at 6:42












    • OK, reverted the -1. Sorry.

      – R..
      Oct 6 '10 at 6:43






    • 1





      You've forgot to define a constructor accepting 3 parameters for struct Data.

      – atzz
      Oct 6 '10 at 6:59











    • @atzz: good catch, I'll add that, though I remember that MSVC could auto initialize without one, can't test that at the moment though

      – Necrolis
      Oct 6 '10 at 7:11












    • 1





      This is not remotely C code.

      – R..
      Oct 6 '10 at 6:40











    • @R.. please read the tags and the OP's post, this is C++ code, like the OP requested

      – Necrolis
      Oct 6 '10 at 6:42












    • OK, reverted the -1. Sorry.

      – R..
      Oct 6 '10 at 6:43






    • 1





      You've forgot to define a constructor accepting 3 parameters for struct Data.

      – atzz
      Oct 6 '10 at 6:59











    • @atzz: good catch, I'll add that, though I remember that MSVC could auto initialize without one, can't test that at the moment though

      – Necrolis
      Oct 6 '10 at 7:11







    1




    1





    This is not remotely C code.

    – R..
    Oct 6 '10 at 6:40





    This is not remotely C code.

    – R..
    Oct 6 '10 at 6:40













    @R.. please read the tags and the OP's post, this is C++ code, like the OP requested

    – Necrolis
    Oct 6 '10 at 6:42






    @R.. please read the tags and the OP's post, this is C++ code, like the OP requested

    – Necrolis
    Oct 6 '10 at 6:42














    OK, reverted the -1. Sorry.

    – R..
    Oct 6 '10 at 6:43





    OK, reverted the -1. Sorry.

    – R..
    Oct 6 '10 at 6:43




    1




    1





    You've forgot to define a constructor accepting 3 parameters for struct Data.

    – atzz
    Oct 6 '10 at 6:59





    You've forgot to define a constructor accepting 3 parameters for struct Data.

    – atzz
    Oct 6 '10 at 6:59













    @atzz: good catch, I'll add that, though I remember that MSVC could auto initialize without one, can't test that at the moment though

    – Necrolis
    Oct 6 '10 at 7:11





    @atzz: good catch, I'll add that, though I remember that MSVC could auto initialize without one, can't test that at the moment though

    – Necrolis
    Oct 6 '10 at 7:11











    0














    Visual Studio, since VS2013, supports Compound literals and Designated initializers.
    Which C99 features are available in the MS Visual Studio compiler?



    Example:



    // main.c
    #include <stdio.h>

    void func(int(*array)[3]);

    int main()

    // Designated initializers

    int a[6] = [4] = 29, [2] = 15 ; // [0, 0, 15, 0, 29, 0]

    struct point int x, y; ;
    struct point p = .y = 13, .x = 27 ; // x = 27, y = 13

    union foo int i; double d; ;
    union foo f = .d = 4 ; // d = 4.0

    struct point ptarray[5] = [2].y = 34, [2].x = 42, [0].x = 58 ;
    // (58 0), (0 0), (42 34), (0 0), (0 0)

    // Compound literals

    int *a1 = NULL;
    a1 = (int[6]) [4] = 29, [2] = 15 ; // [0, 0, 15, 0, 29, 0]

    struct point p1;
    p1 = (struct point) .y = 13, .x = 27 ; // x = 27, y = 13

    union foo f1;
    f1 = (union foo) .d = 4 ; // d = 4.0

    struct point *ptarray1 = NULL;
    ptarray1 = (struct point[5]) [2].y = 34, [2].x = 42, [0].x = 58 ;
    // (58 0), (0 0), (42 34), (0 0), (0 0)

    int *p2 = NULL;
    p2 = (int[2]) -1 ;
    p2 = (int) -73, 89, 92 ;
    func(&(int) -73, 89, 92 );

    return 0;


    void func(int(*array)[3])

    for (int i = 0; i < 3; i++)
    printf("%d ", (*array)[i]);







    share|improve this answer





























      0














      Visual Studio, since VS2013, supports Compound literals and Designated initializers.
      Which C99 features are available in the MS Visual Studio compiler?



      Example:



      // main.c
      #include <stdio.h>

      void func(int(*array)[3]);

      int main()

      // Designated initializers

      int a[6] = [4] = 29, [2] = 15 ; // [0, 0, 15, 0, 29, 0]

      struct point int x, y; ;
      struct point p = .y = 13, .x = 27 ; // x = 27, y = 13

      union foo int i; double d; ;
      union foo f = .d = 4 ; // d = 4.0

      struct point ptarray[5] = [2].y = 34, [2].x = 42, [0].x = 58 ;
      // (58 0), (0 0), (42 34), (0 0), (0 0)

      // Compound literals

      int *a1 = NULL;
      a1 = (int[6]) [4] = 29, [2] = 15 ; // [0, 0, 15, 0, 29, 0]

      struct point p1;
      p1 = (struct point) .y = 13, .x = 27 ; // x = 27, y = 13

      union foo f1;
      f1 = (union foo) .d = 4 ; // d = 4.0

      struct point *ptarray1 = NULL;
      ptarray1 = (struct point[5]) [2].y = 34, [2].x = 42, [0].x = 58 ;
      // (58 0), (0 0), (42 34), (0 0), (0 0)

      int *p2 = NULL;
      p2 = (int[2]) -1 ;
      p2 = (int) -73, 89, 92 ;
      func(&(int) -73, 89, 92 );

      return 0;


      void func(int(*array)[3])

      for (int i = 0; i < 3; i++)
      printf("%d ", (*array)[i]);







      share|improve this answer



























        0












        0








        0







        Visual Studio, since VS2013, supports Compound literals and Designated initializers.
        Which C99 features are available in the MS Visual Studio compiler?



        Example:



        // main.c
        #include <stdio.h>

        void func(int(*array)[3]);

        int main()

        // Designated initializers

        int a[6] = [4] = 29, [2] = 15 ; // [0, 0, 15, 0, 29, 0]

        struct point int x, y; ;
        struct point p = .y = 13, .x = 27 ; // x = 27, y = 13

        union foo int i; double d; ;
        union foo f = .d = 4 ; // d = 4.0

        struct point ptarray[5] = [2].y = 34, [2].x = 42, [0].x = 58 ;
        // (58 0), (0 0), (42 34), (0 0), (0 0)

        // Compound literals

        int *a1 = NULL;
        a1 = (int[6]) [4] = 29, [2] = 15 ; // [0, 0, 15, 0, 29, 0]

        struct point p1;
        p1 = (struct point) .y = 13, .x = 27 ; // x = 27, y = 13

        union foo f1;
        f1 = (union foo) .d = 4 ; // d = 4.0

        struct point *ptarray1 = NULL;
        ptarray1 = (struct point[5]) [2].y = 34, [2].x = 42, [0].x = 58 ;
        // (58 0), (0 0), (42 34), (0 0), (0 0)

        int *p2 = NULL;
        p2 = (int[2]) -1 ;
        p2 = (int) -73, 89, 92 ;
        func(&(int) -73, 89, 92 );

        return 0;


        void func(int(*array)[3])

        for (int i = 0; i < 3; i++)
        printf("%d ", (*array)[i]);







        share|improve this answer















        Visual Studio, since VS2013, supports Compound literals and Designated initializers.
        Which C99 features are available in the MS Visual Studio compiler?



        Example:



        // main.c
        #include <stdio.h>

        void func(int(*array)[3]);

        int main()

        // Designated initializers

        int a[6] = [4] = 29, [2] = 15 ; // [0, 0, 15, 0, 29, 0]

        struct point int x, y; ;
        struct point p = .y = 13, .x = 27 ; // x = 27, y = 13

        union foo int i; double d; ;
        union foo f = .d = 4 ; // d = 4.0

        struct point ptarray[5] = [2].y = 34, [2].x = 42, [0].x = 58 ;
        // (58 0), (0 0), (42 34), (0 0), (0 0)

        // Compound literals

        int *a1 = NULL;
        a1 = (int[6]) [4] = 29, [2] = 15 ; // [0, 0, 15, 0, 29, 0]

        struct point p1;
        p1 = (struct point) .y = 13, .x = 27 ; // x = 27, y = 13

        union foo f1;
        f1 = (union foo) .d = 4 ; // d = 4.0

        struct point *ptarray1 = NULL;
        ptarray1 = (struct point[5]) [2].y = 34, [2].x = 42, [0].x = 58 ;
        // (58 0), (0 0), (42 34), (0 0), (0 0)

        int *p2 = NULL;
        p2 = (int[2]) -1 ;
        p2 = (int) -73, 89, 92 ;
        func(&(int) -73, 89, 92 );

        return 0;


        void func(int(*array)[3])

        for (int i = 0; i < 3; i++)
        printf("%d ", (*array)[i]);








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 16 '18 at 4:32

























        answered Nov 16 '18 at 4:26









        infvalinfval

        32




        32



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3869963%2fcompound-literals-in-msvc%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            政党

            天津地下鉄3号線