Microchip
直播中

韩婧

7年用户 173经验值
私信 关注
[问答]

Sizeof不适用于类型,只适用于变量?

嗨,Sizeof不使用类型,只使用变量。我希望下面的代码工作,但它不起作用。为了工作,我必须做以下的调整(我觉得很可怕):谁能给我一个提示,或者告诉我如何做类型的工作。谢谢。

以上来自于百度翻译


      以下为原文

   
Hi,
Sizeof does not work with types, only with variables.
I expected the code below to work, but it does not work.

#define NAME_TASK_SIZE (16)
typedef struct {
        unsigned char name[NAME_TASK_SIZE];
        float descida;
        float descanso;
        float subida;
}t_tupla;


void DATABASE_Delete(unsigned char index)
{
    unsigned char i;
    for(i=0;i<(sizeof t_tupla);i++)
        EEPROM_Write_Byte(((sizeof t_tupla)*index)+3+i,0xFF);
}


To work I had to make the following adaptation (which I found horrible):

void DATABASE_Delete(unsigned char index)
{
    unsigned char i;
    t_tupla var;
    for(i=0;i<(sizeof var);i++)
        EEPROM_Write_Byte(((sizeof var)*index)+3+i,0xFF);
}



Can anyone give me a hint or tell how to do sizeof work with types.

Thank you.

回帖(1)

殷谷光

2018-12-27 16:26:12
嗨,现在开始工作了。谢谢你:

以上来自于百度翻译


      以下为原文

    Hi,
It's working now. Thank you
grin:
It's working now. Thank you
举报

更多回帖

发帖
×
20
完善资料,
赚取积分