What is the purpose of ANYSIZE_ARRAY in ?

前端 未结 2 618
北荒
北荒 2021-01-18 14:21

What\'s the purpose of ANYSIZE_ARRAY, located in WinNT.h?

I see an MSDN blog post about it from 2004 but it doesn\'t make sense to me.

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-18 14:57

    I assume you are talking about this blog post.

    It is often used when a variable-sized (unknown at compile time) array is part of a struct:

    typedef struct {
        int CommonFlags
        int CountOfThings;
        THING Things[ANYSIZE_ARRAY]; //Things[1];
    } THINGSANDFLAGS;
    

    To work with those structures you often first call the desired API to get the size of the data, then allocate a block of memory big enough and finally call the same API again so it can fill in the data...

提交回复
热议问题