does anyone know, why the following codes is crashing, when it is compiled with g++?
#include <iostream>
unsigned long getSumDivisors(const unsigned long number) {
unsigned long sum = 0;
for(unsigned long i = 0; i < number; ++ i) {
if(number % i == 0) {
sum += i;
}
}
return sum;
}
int main() {
std::cout << getSumDivisors(5);
return 0;
}
when i remove sum += i; it wont crash.
I tried to compile it under windows and linux linaro with
g++ (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3 Copyright © 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
and
g++ (tdm-2) 4.8.1 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.