中 ANYSIZE_ARRAY 的用途是什么?

发布于 2025-01-03 20:32:19 字数 103 浏览 5 评论 0 原文

位于 WinNT.h 中的 ANYSIZE_ARRAY 的用途是什么?

我在 2004 年看到一篇关于它的 MSDN 博客文章,但它对我来说没有意义。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

廻憶裏菂餘溫 2025-01-10 20:32:19

我假设您正在谈论 这篇博文

当可变大小(编译时未知)数组是结构的一部分时,通常会使用它:

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

要使用这些结构,您通常首先调用所需的 API 来获取数据的大小,然后分配足够大的内存块最后再次调用相同的 API,以便它可以填充数据......

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

无言温柔 2025-01-10 20:32:19

来自此页面

在 C 中,可变大小数组声明为 a[1]a[ANYSIZE_ARRAY],其中 ANYSIZE_ARRAY 定义为<代码>1。然后使用它,就好像它更大一样。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文