[C语言]对一段连续内存,多个结构体赋值的一种手段

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned char       UINT8;
  
typedef struct {
  UINT8 Type;       ///< 0x01 Hardware Device Path.
                    ///< 0x02 ACPI Device Path.
                    ///< 0x03 Messaging Device Path.
                    ///< 0x04 Media Device Path.
                    ///< 0x05 BIOS Boot Specification Device Path.
                    ///< 0x7F End of Hardware Device Path.

  UINT8 SubType;    ///< Varies by Type
                    ///< 0xFF End Entire Device Path, or
                    ///< 0x01 End This Instance of a Device Path and start a new
                    ///< Device Path.

  UINT8 Length[2];  ///< Specific Device Path data. Type and Sub-Type define
                    ///< type of data. Size of data is included in Length.
                    //Length[0]: low 8 bytes, Length[1]: high 8 bytes

} EFI_DEVICE_PATH_PROTOCOL;


int main()
{
    int aaa = 2;
    int bbb = 3;
    unsigned char s[30];
    memset(s, 0, 30);
    
    EFI_DEVICE_PATH_PROTOCOL *p = (EFI_DEVICE_PATH_PROTOCOL *)s;
    p->Type = 1;
    p->SubType = 2;
    p->Length[0] = 3;
    p->Length[1] = 4;
    
    
    p = (EFI_DEVICE_PATH_PROTOCOL *)(s + 15);
    p->Type = 1;
    p->SubType = 2;
    p->Length[0] = 3;
    p->Length[1] = 4;
    
    for(int i=0;i<30;i++)
    {
        printf("%d: %c %u\n", i+1, s[i], s[i]);
        //TODO
    }    
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值