C pointer query

Thread Starter

aamirali

Joined Feb 2, 2012
412
1. here is pice of code, x incremnts. this is way how to call by referernece
This is fine
Rich (BB code):
main()
{
     int x;
     inc(&x);
}

inc(int * y)
{
    (*y)++;
}
2. Second, how does i is treated here. Do i passes address now to eeAddress.
Like eeAddress has address of i. And try to change value of eeAddress like let have i =0 *eeAddress is value at address 0 of MCU

Rich (BB code):
i=0;
writeEEPROM( (uint8_t*) i, (uint8_t*) &hold, 4 );


void writeEEPROM( uint8_t* eeAddress, uint8_t* buffAddress, uint32_t byteCount )
{	
	unsigned int command[5], result[4];	

	command[0] = 61;                  
	command[1] = (uint32_t) eeAddress;
	command[2] = (uint32_t) buffAddress;
	command[3] = byteCount;            
	command[4] = SystemCoreClock/1000;
	
	/* Invoke IAP call...*/
	iap_entry(command, result);
	if (0 != result[0])
	{
		//Trap error
		while(1);
	}
	return;
}
 

tshuck

Joined Oct 18, 2012
3,534
I'm not sure what your question is here... this is expected behavior....in 2, you are casting the i variable to become a pointer, indicating the value of i is an address. eeAddress will point to the address i, so if i = 100, eeAddress will point to the data stored at 100...
 
Top