hendrikschnack
hendrikschnack

Reputation: 77

Different size pointer cast warning in ARM64 system

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?

Upvotes: 1

Views: 453

Answers (1)

hendrikschnack
hendrikschnack

Reputation: 77

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!

Upvotes: 1

Related Questions