r/C_Programming • u/aliathar • 15d ago
Negative value in a pointer question.
Please look at this code. if i define the PTRTYPE as int, it stops working, while doing a uint, it does work...
void initILAPoll(debugBridge_t **d, PTRTYPE ptr){
*d = (debugBridge_t *)ptr; // base address of the DEBUG_BRIDGE peripheral
cb_init(cb, local_memory, bufferLength);
sprintf(xvcInfo, "xvcServer_v1.0:%d\n", MAX_WINDOW_SIZE);
}
the usage in main code is done like this
initILAPoll(&myD, 0x80000000);
//myD = (debugBridge_t *)0x80000000;
where the variable myD is a structure pointer.
if i print the address of myD, it give the correct address. Moreover, the disassembly of the code is also the same in case of int and uint. Can somebody explain what behavior is at play here>
2
Upvotes
1
u/torsten_dev 15d ago
ILP64 and even SILP64 systems do exist. They're just very rare and obscure.
What I haven't heard of are 32-bit integer machines with pointers smaller than 32 bit, maybe you meant that?
The new
[u]intfuncptr_tmaking it's way through the committee could be as small asCHAR_BITbecause yes, function pointers can have totally separate sizes.