C pointer query

Discussion in 'Programmer's Corner' started by aamirali, Nov 20, 2012.

  1. aamirali

    Thread Starter Member

    Feb 2, 2012
    415
    1
    1. here is pice of code, x incremnts. this is way how to call by referernece
    This is fine
    Code ( (Unknown Language)):
    1.  
    2.  
    3. main()
    4. {
    5.      int x;
    6.      inc(&x);
    7. }
    8.  
    9. inc(int * y)
    10. {
    11.     (*y)++;
    12. }
    13.  
    14.  
    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

    Code ( (Unknown Language)):
    1.  
    2.  
    3. i=0;
    4. writeEEPROM( (uint8_t*) i, (uint8_t*) &hold, 4 );
    5.  
    6.  
    7. void writeEEPROM( uint8_t* eeAddress, uint8_t* buffAddress, uint32_t byteCount )
    8. {  
    9.     unsigned int command[5], result[4];
    10.  
    11.     command[0] = 61;                  
    12.     command[1] = (uint32_t) eeAddress;
    13.     command[2] = (uint32_t) buffAddress;
    14.     command[3] = byteCount;            
    15.     command[4] = SystemCoreClock/1000;
    16.    
    17.     /* Invoke IAP call...*/
    18.     iap_entry(command, result);
    19.     if (0 != result[0])
    20.     {
    21.         //Trap error
    22.         while(1);
    23.     }
    24.     return;
    25. }
    26.  
    27.  
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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...
     
Loading...