Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I run a baremetal Xilinx-based ARM A57 system.

I want to bring the addresses of two linker-defined symbols to my c program...

This is the linker script:

.mutex_ram: {
     _mutex_start = .;
     . += _MUTEX_SIZE;
     . = ALIGN(8);
     _mutex_end = .;
} > mem_common

This is a brief summary of what I want to do in C.

extern int _mutex_start;
extern int _mutex_end;
void some_fcn(void) 
{
    int size = (int)(&_mutex_end)-(int)(&_mutex_start);
    memset(&_mutex_start,0,size);
}

Why the heck does the compiler warn me that this is a different-size integer cast? I just don't get it...

warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]

Can somebody help me?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
483 views
Welcome To Ask or Share your Answers For Others

1 Answer

Thanks to Jabberwocky, I used

ptrdiff_t size = (ptrdiff_t)((intptr_t)&_mutex_end -  (intptr_t)&_mutex_start);

I wasn't aware that using ptr_diff_t is actually MISRA-compliant... Thanks for the help!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...