mike-matera / ArduinoSTL

An STL and iostream implementation based on uClibc++ that supports my CS-11M class.
GNU General Public License v3.0
325 stars 80 forks source link

Correct array initialisation #81

Open ngraziano opened 2 years ago

ngraziano commented 2 years ago

std::array<int,5> test={ 1 }; should fill element 1 to 4 with 0;

In other library the member data element is public to allow compiler to fill it directly. Use same principle.

A code example that test this:

#ifdef ARDUINO
#include <ArduinoSTL.h>
#endif

#include <array>
#include <iostream>

std::array<int16_t, 8> test_array;

void test()
{
  test_array = {0, 1, 2, 3, 4, 5, 6, 7};
  std::cout << "Value shoud be 0 1 2 3 4 5 6 7  : ";
  for (auto values : test_array)
  {
    std::cout << values << " ";
  }
  std::cout << std::endl;

  test_array = {5, 5};

  std::cout << "Value shoud be 5 5 0 0 0 0 0 0  : ";
  for (auto values : test_array)
  {
    std::cout << values << " ";
  }
  std::cout << std::endl;
}

#ifdef ARDUINO
void setup()
{
  Serial.begin(115200);
}

void loop()
{
  test();
}
#else
int main(int argc, char **args)
{
  while(true)
    test();
}
#endif