user19933: I got the following error:
warning: variable 'b' set but not used.
I think I do a really small thing wrong but I can't figure out what it is.
#define array_size(array) ((int)(sizeof(array) / sizeof((array)[0])))

typedef struct Boid {
  unsigned long start_animate_time;
} Boid;

Boid boids[4];


Boid create_boid() {
  unsigned long start_animate_time = 0L; 
  Boid b = {start_animate_time};
  return b;
}


void setup() {
  Serial.begin(9600);

  boids[0] = create_boid();
  boids[1] = create_boid();
  boids[2] = create_boid();
  boids[3] = create_boid();

  for (int i = 0; i < array_size(boids); i++) {
    Boid b = boids[i]; // <<<<<<<<<<<<< this line!
    b.start_animate_time = 456;
  } 


  for (int i = 0; i < array_size(boids); i++) {
    Boid b = boids[i];
    Serial.println(b.start_animate_time); // BUG always 0
  }
}


void loop() {

}


flock_01_ino_debug.ino:28:10: warning: variable 'b' set but not used
  [-Wunused-but-set-variable]
       Boid b = boids[i];
            ^


user4143: C++ is not Java. You can't just assign structs like that - it copies them (if anything).
Boid b = boids[I]; // <<<<<<<<<<<<< this line!
b.start_animate_time = 456;

Instead just access the array slice directly:
boids[i].start_animate_time = 456;

And later on as well:
Serial.println(boids[i].start_animate_time);

Basically, you create a "Boid" variable called "b", copy the content of boids[i] to it, set a value in that variable, and then throw it away. Hence the "not used". If you want to reference a specific array slice as a separate variable either get a pointer to it:
Boid *b = &boids[i];
b->start_animate_time = 456;

Or use a reference:
Boid &b = boids[i];
b.start_animate_time = 456;

Of the two I prefer using a pointer, but I come from a C background and understand pointers, but it took me many years of trial and error to get to that point...

19933: <p>I got the following error:</p>

<p><code>warning: variable 'b' set but not used</code>.</p>

<p>I think I do a really small thing wrong but I can't figure out what it is.</p>

<pre><code>#define array_size(array) ((int)(sizeof(array) / sizeof((array)[0])))

typedef struct Boid {
  unsigned long start_animate_time;
} Boid;

Boid boids[4];


Boid create_boid() {
  unsigned long start_animate_time = 0L; 
  Boid b = {start_animate_time};
  return b;
}


void setup() {
  Serial.begin(9600);

  boids[0] = create_boid();
  boids[1] = create_boid();
  boids[2] = create_boid();
  boids[3] = create_boid();

  for (int i = 0; i &lt; array_size(boids); i++) {
    Boid b = boids[i]; // &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; this line!
    b.start_animate_time = 456;
  } 


  for (int i = 0; i &lt; array_size(boids); i++) {
    Boid b = boids[i];
    Serial.println(b.start_animate_time); // BUG always 0
  }
}


void loop() {

}
</code></pre>

<blockquote>
  <p>flock_01_ino_debug.ino:28:10: warning: variable 'b' set but not used
  [-Wunused-but-set-variable]
       Boid b = boids[i];
            ^</p>
</blockquote>
 4143: <p>C++ is not Java. You can't just assign structs like that - it copies them (if anything).</p>

<pre><code>Boid b = boids[I]; // &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; this line!
b.start_animate_time = 456;
</code></pre>

<p>Instead just access the array slice directly:</p>

<pre><code>boids[i].start_animate_time = 456;
</code></pre>

<p>And later on as well:</p>

<pre><code>Serial.println(boids[i].start_animate_time);
</code></pre>

<p>Basically, you create a "Boid" variable called "b", copy the content of <code>boids[i]</code> to it, set a value in that variable, and then throw it away. Hence the "not used". If you want to reference a specific array slice as a separate variable either get a pointer to it:</p>

<pre><code>Boid *b = &amp;boids[i];
b-&gt;start_animate_time = 456;
</code></pre>

<p>Or use a reference:</p>

<pre><code>Boid &amp;b = boids[i];
b.start_animate_time = 456;
</code></pre>

<p>Of the two I prefer using a pointer, but I come from a C background and understand pointers, but it took me many years of trial and error to get to that point...</p>
