gpt4 book ai didi

c - 在 C 中,使用同一结构内的另一个值设置结构内数组的大小

转载 作者:太空宇宙 更新时间:2023-11-04 05:26:23 25 4
gpt4 key购买 nike

    struct {
uint16 msg_length;
uint8 msg_type;
ProtocolVersion version;
uint16 cipher_spec_length;
uint16 session_id_length;
uint16 challenge_length;
V2CipherSpec cipher_specs[V2ClientHello.cipher_spec_length];
opaque session_id[V2ClientHello.session_id_length];
opaque challenge[V2ClientHello.challenge_length;
} V2ClientHello;

是否可以做类似上面的事情(https://www.rfc-editor.org/rfc/rfc5246)?如果是这样,我该如何在 C 中对此进行编码?

更具体地说,结构中的这一行:

V2CipherSpec cipher_specs[V2ClientHello.cipher_spec_length];


用途:
> V2ClientHello.cipher_spec_length
这是在同一个结构体中定义的,用来设置数组的长度。

最佳答案

C 不支持动态大小的数组。为实现您的目标,您可以使用 V2CipherSpec 类型的指针作为结构变量,并在稍后阶段使用 V2ClientHello.cipher_spec_length 值分配内存。

关于c - 在 C 中,使用同一结构内的另一个值设置结构内数组的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25763343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com