Heap on Mac and Linux

Some caveats about heap on mac and linux

#include <iostream>

int main() {

   double *a = new double[5];

   for(auto i = 0; i < 5; i++)
   {
     a[i] = i;
   }

   std::cout << a[-10] << std::endl;

}

This program runs on Mac without warning or error. However, it gives segmentation fault (core dump) error on ubuntu and cent os.

Planted: by ;

L Ma (2017). 'Heap on Mac and Linux', Datumorphism, 09 April. Available at: https://datumorphism.leima.is/til/programming/cpp/cpp-heap-mac-linux-diff/.