小编Laz*_*zar的帖子

C中的结构声明和定义

如果我们这样写:

typedef struct 
{
    unsigned int counter;
} MyStruct;
Run Code Online (Sandbox Code Playgroud)

这代表结构声明?

声明说我们的编译器在某处有一个结构,其参数的类型和大小与上述类似,并且在声明的情况下,在内存中没有为该结构保留空间。

定义是,因为现在我们在内存中为我们的结构保留了一个空间:

MyStruct tmpStruct;
Run Code Online (Sandbox Code Playgroud)

还是我错了?

请用结构说明情况。

c struct compilation declaration definition

2
推荐指数
1
解决办法
7284
查看次数

投射到指针警告

我将变量display_address,version,serial_no []定义为uint8_t并将其转发给函数,该变量需要为指针,因此我将其强制转换为(uint8_t *)变量,此后,我得到警告

警告:从较小的整数类型uint8_t(又名“ unsigned char”)转换为“ uint8_t *”(又名“ unsigned char *”)

有什么问题,为什么这行不通?

这是我要转发参数的函数

void write_to_flash (void)    {                     
BYTE i;

    iap_copy_to_flash((uint8_t *)display_address, OFFSET_ADDRESS, 1); //warning here
    delay_1_ms();
    iap_copy_to_flash((uint8_t *)version, OFFSET_VERSION, 1); //warning here
    delay_1_ms();
    for (i=0;i<8;i++)     {
        iap_copy_to_flash((uint8_t *)serial_no[i], OFFSET_VERSION+i, 1); //warning here
        delay_1_ms();
        }
    }
Run Code Online (Sandbox Code Playgroud)

和iap_copy_to_flash参数说明

void iap_copy_to_flash (uint8_t* buff, uint32_t flash_addr, uint32_t num_bytes)
Run Code Online (Sandbox Code Playgroud)

c embedded

0
推荐指数
1
解决办法
3225
查看次数

标签 统计

c ×2

compilation ×1

declaration ×1

definition ×1

embedded ×1

struct ×1