felixhao28 / JSCPP

A simple C++ interpreter written in JavaScript

Home Page:https://felixhao28.github.io/JSCPP/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uninitialized array

smoutault opened this issue · comments

It seems to me that there is an error with uninitialized arrays. Elements should not be initialized to 0 as is currently the case seems to me.
For example :
#include <stdio.h>

int main() {
float tab[2];
for(int i = 0; i < 2; i++){
printf("%f, ", tab[i]);
}
return 0;
}
gives 0.00000, 0.00000 instead of NaN, NaN.

The C99 standard says that "if an object that has an automatic storage duration is not explicitly initialized, its value is undetermined." I think it's the same in C++ (or not ?).

Yes defaulting to zero can hide potential errors. I will use NaN instead. Thanks.