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; }
The purpose of a NULL pointer is not to cause a processor exception when it is dereferenced (although that is nice to have for debugging.) Its purpose is to serve as a special value for a pointer that could indicate a special condition in your program. You can compare a pointer with NULL to test for the special condition. The standard says that it 'is guaranteed to compare unequal to a pointer to any object or function'. It's OK if it points to internal RAM. In this case, the linker must ensure that no object in the program is located at this address. It is sufficient to reserve 1 byte at this address. Apparently, Keil failed to do that with C51.