What happens if i try to write data to memory location where NULL POINTER is pointing, in ARM? _my understanding_ The Null Pointer is a Pointer pointing to 0. Does that mean memory location 0x0(the reset vector address, writing to this memory location is definitely not possible without IAP. so it may not be pointing 0x00 memory address)?
Or does it mean that the Pointer is pointing to nothing? If pointer is pointing to nothing, then where is the data being written in the following code if pQEI becomes a NULL POINTER?
void QEI_Init(uint8_t qeiId, QEI_CFG_Type *QEI_ConfigStruct) { LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId); pQei->MAXPOS = 0x00; pQei->CMPOS0 = 0x00; //where is 0x00 being written if the pQEI becomes NULL POINTER . . . /* an so on*/ } LPC_QEI_TypeDef* QEI_GetPointer(uint8_t qeiId) { LPC_QEI_TypeDef* pQei = NULL; if(qeiId == 0) { pQei = LPC_QEI; } return pQei; }
"Thats why i wanted to know, where does NULL POINTER Point to?"
As I said: That depends on the context, i.e. what type of pointer you have that you assign NULL to. It is the pointer type that decides what memory address space the pointer associates to. So it is the pointer type that decides if NULL will point somewhere in code or internal or external RAM.
Why do you say "which should never happen"? NULL pointers are regularly used. Just that NULL pointer indirection is almost always a big fail (with the exception of architecture-specific code that just happens to know there are memory that needs to be accessed at the same address as a NULL pointer will access - but such architecture-specific code should be avoided when possible).
When traversing data structures, it is very common that a pointer to the current (or maybe next) object is returned. And at end of traverse, a NULL pointer is returned to inform the loop that it should end the traversal.
And it is relevant to have NULL pointers to code space, in case the the source makes use of function pointers, to signal that a specific action doesn't have any function pointer registered.
And it is relevant to have NULL pointers to data space.
It is common - but not required that a NULL pointer happens to be offset 0 of the relevant address space. It depends on architecture and compiler - some architectures even have magic binary values that represents NULL. So any specific debate about binary values of NULL pointers or where they actually point has to be in relation to a specific architecture and/or compiler.
Since offset 0 is normally used, lots of compilers/startup files tries to place other information at offset 0, to make sure that the end-users variables will not happen to be stored at address 0, making &my_var happen to get the same binary value as a NULL pointer.