嵌入式3-12

1.整理思维导图

2.把上课没做完的结构体大小求完(写出过程)

3.把枚举部分的练习题,再做一遍

4.三种验证大小端存储大的代码写一遍

1.思维导图在最后
2.结构体大小

struct data{                1233000044444444,16字节
char t1;
char t2;
unsigned short t3;
unsigned long t4;
};

struct data{                100022223300,12字节
char t1;
int t2;
short t3;
};

struct s1                      100022223000,12字节
{
char c1;
int i;
char c2;
};


struct s2                       12003333,8字节
{
char c1;
char c2;
int i;
};

typedef struct Test       1100000000002222222222223333,28字节
{

short a;
        struct                    111122223000,12字节
        {
        int b;
        double c;
        char d;
        }p;
int e;
}Test;

typedef struct Test            2+6+96+4+4,112字节
{
short a;
        struct                         4+4+80+1+7,96字节
        {
        int b;
        double c[10];
        char d;
        };
int e;
}Test;

struct c{                100022223300,12字节
char b;
int a;
short c;
};

struct c{                12223,5字节
char a;
char b[3];
char c;
};

typedef struct        4+1+3+8+1+3+4+8,32字节
{
int b;
char a;
long e;
char c;
float d;
double t;
}node;

3.枚举
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
typedef enum
{
    LED_1,
    LED_2,
    LED_3
}LED;
typedef enum
{
    ON,
    OFF
}LED_CON;
void init(LED L)
{
    switch(L)
    {
        case LED_1:
            printf("初始化了LED_1灯\n");
            break;    
        case LED_2:
            printf("初始化了LED_2灯\n");
            break;
        case LED_3:
            printf("初始化了LED_3灯\n");
            break;
    }
}
void con(LED L,LED_CON C)
{
    switch(L)
    {
        case LED_1:
            switch(C)
            {
                case ON:
                    printf("打开了LED_1灯\n");
                    break;
            }
            break;    
        case LED_2:
            switch(C)
            {
                case ON:
                    printf("打开了LED_2灯\n");
                    break;
            }
            break;    
        case LED_3:
            switch(C)
            {
                case ON:
                    printf("打开了LED_3灯\n");
                    break;
            }
            break;    
    }
}
int main(int argc, const char *argv[])
{
    init(LED_1);
    con(LED_2,ON);
    return 0;
}

4.大小端存储

一、
int a=0x12345678;

char c=(char)a;

if(c==0x12)

{

        printf("大端存储\n");

}else{

        printf("小端存储\n");

}

二、

typedef union

{

        short a;

        char c;

}A;

A u.a=0x1234

if(u.c==0x12)

{

        printf("大端存储\n");

}else{

        printf("小端存储\n");

}

  • 21
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值