-1

I have written a function and asked some questions here about it. It works very well, I can call it and use it. But something has confused my mind. Here is the function prototype which I just mentioned:

void writeToEEPROM( uint8 srcBuf[], uint32 byteCount, int writePtr);

I can call this function by sending my array to it, like this:

uint8 mysrcBuf[10];

writeToEEPROM(mysrcBuf,10,0);  // This is working.

In the function prototype, it gets *srcBuff and ,as I know, *srcBuff is the value in the address of srcBuff. I mean, asteriks(*) operand actually reads the value of that address, doesn't it? But I am sending mysrcBuf which is the address for the first element of the array.

If i declare the function like below, it still works:

void writeToEEPROM( uint8 * srcBuf, uint32 byteCount, int writePtr);

Are these statements same?:

uint8 srcBuf[] and uint8 * srcBuf

It does not warn me or cause problems if I change the declaration and call it with same way.

(Sorry if there is a duplicate of this question. I have searched pointers a lot. But it still confuses me sometimes.)

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
abdullah cinar
  • 543
  • 1
  • 6
  • 20
  • 1
    Did you search before posting? – trojanfoe Feb 09 '16 at 08:26
  • 1
    See [difference-between-passing-array-and-array-pointer-into-function-in-c](http://stackoverflow.com/questions/5573310/difference-between-passing-array-and-array-pointer-into-function-in-c) – Rishikesh Raje Feb 09 '16 at 08:27
  • 1
    Related: [Similarities and differences between arrays and pointers through a practical example](http://stackoverflow.com/questions/1782369). – DevSolar Feb 09 '16 at 08:31
  • @trojanfoe Yes ,as i said, i searched before posting. But some people can have difficulties while trying to find the similar questions; especially if they don't have the deep technical knowledge and language skills to find the "key"words. I didn't know what `decaying` means before, and now i learned it. So i can approve that question as duplicate and people can find that question through my question, right? I can not prove to you how many questions that i searched till here... – abdullah cinar Feb 09 '16 at 08:38

2 Answers2

1

In your case,

void writeToEEPROM( uint8 srcBuf[], uint32 byteCount, int writePtr);

and

void writeToEEPROM( uint8 *srcBuf, uint32 byteCount, int writePtr);

will be same, as when arrays are passed as function arguments, they decay to the address of the first element. So, both the representations will be okay to receive the same.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
-3

They are the same but uint8 * srcBuf is more accurate.

i486
  • 6,491
  • 4
  • 24
  • 41