user48730: I'm trying to log reconnections and disconnections of a network. For that I've created 2 time_t arrays to store such occurances:
const int logSize = 10;
time_t conLog[logSize];
time_t disconLog[logSize];

Now, down the road, I have some manipulation and time calculation to do, and for that I wish to pass those log as a variable.
For example - zeroing its values:
void initLog(time_t log[], time_t init_val = 0)
{
        int sizeLog = sizeof(log) / sizeof(log[0]);
        Serial.print("size: ");
        Serial.println(sizeLog);
        for (int i = 0; i < sizeLog; i++)
        {
                log[i] = init_val;
        }
}

in order using it in a simple way : initLog(conLog);
But unfortunately this is wrong.
I've tried to replace time_t log[] with time_t &log - but still no luck.
What do I do wrong ?

user4143: When you pass an array to a function it "collapses" the array into just a pointer. All the receiving function knows is the type of the contents of the array (time_t) and where it starts in memory - it knows nothing about the size of the array.
The sizeof() call just gives you the size of that pointer, not the size of the memory it points to.
sizeof() is not actually a function, it's a compile-time construct. It can't know anything about runtime values, only what is there at compile time.
Instead you must pass the length of the array with the array as a separate parameter, which can only be calculated in the same scope as where the array is defined, and then only by using the original name of the array.  It is typical to create a macro to do this for you at the time you make the array:
time_t conLog[logSize];
#define CONLOG_SIZE (sizeof(conLog) / sizeof(conLog[0]))

Then pass that to your function:
initLog(conLog, CONLOG_SIZE);

Alternatively, since you already have the size in a constant in this case, you could just use that:
initLog(conLog, logSize);


48730: <p>I'm trying to log reconnections and disconnections of a network. For that I've created 2 <code>time_t</code> arrays to store such occurances:</p>
<pre><code>const int logSize = 10;
time_t conLog[logSize];
time_t disconLog[logSize];
</code></pre>
<p>Now, down the road, I have some manipulation and time calculation to do, and for that I wish to pass those log as a variable.</p>
<p>For example - zeroing its values:</p>
<pre><code>void initLog(time_t log[], time_t init_val = 0)
{
        int sizeLog = sizeof(log) / sizeof(log[0]);
        Serial.print(&quot;size: &quot;);
        Serial.println(sizeLog);
        for (int i = 0; i &lt; sizeLog; i++)
        {
                log[i] = init_val;
        }
}
</code></pre>
<p>in order using it in a simple way : <code>initLog(conLog);</code>
But unfortunately this is wrong.</p>
<p>I've tried to replace <code>time_t log[]</code> with <code>time_t &amp;log</code> - but still no luck.</p>
<p>What do I do wrong ?</p>
 4143: <p>When you pass an array to a function it &quot;collapses&quot; the array into just a pointer. All the receiving function knows is the type of the contents of the array (<code>time_t</code>) and where it starts in memory - it knows nothing about the size of the array.</p>
<p>The <code>sizeof()</code> call just gives you the size of that pointer, not the size of the memory it points to.</p>
<p><code>sizeof()</code> is not actually a function, it's a compile-time construct. It can't know anything about runtime values, only what is there at compile time.</p>
<p>Instead you must pass the length of the array with the array as a separate parameter, which can only be calculated in the same scope as where the array is defined, and then only by using the original name of the array.  It is typical to create a macro to do this for you at the time you make the array:</p>
<pre><code>time_t conLog[logSize];
#define CONLOG_SIZE (sizeof(conLog) / sizeof(conLog[0]))
</code></pre>
<p>Then pass that to your function:</p>
<pre><code>initLog(conLog, CONLOG_SIZE);
</code></pre>
<p>Alternatively, since you already have the size in a constant in this case, you could just use that:</p>
<pre><code>initLog(conLog, logSize);
</code></pre>
