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


    #include
    #include
    #include

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


     

  • 相关阅读:
    【无标题】
    类图复习:类图简单介绍
    RK3568驱动指南|第七期-设备树-第56章 设备树基本语法
    行为学派 进化计算
    第一章 Redis基础
    详解设计模式:简单工厂模式
    搜索与图论-树与图的广度优先遍历
    MQTT X 1.9.0 发布:开箱即用的 bench 命令,MQTT 性能测试更便捷
    前端文件上传
    js使用构造函数的注意点?
  • 原文地址:https://blog.csdn.net/r77683962/article/details/126299451