What is the purpose of ANYSIZE_ARRAY in <winnt.h>?

巧了我就是萌 提交于 2019-12-01 17:57:56

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...

From this page:

In C, a variable-size array is declared as a[1] or a[ANYSIZE_ARRAY], where ANYSIZE_ARRAY is defined as 1. Then it is used as if it were bigger.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!