jeudi 31 mars 2016

`#define` a very large number in c++ source code

Well, the question is not as silly as it sound.

I am using C++11 <array> and want to declare an array like this:

array<int, MAX_ARR_SIZE> myArr;

The MAX_ARR_SIZE is to be defined in a header file and could be very large i.e. 10^15. Currently I am typing it like a pre-school kid

 #define MAX_ARR_SIZE 1000000000000000

I can live with it if there is no alternative. I can't use pow(10, 15) here since it can not be evaluated at compile time; array initialization will fail. I am not aware of any shorthand to type this.

Aucun commentaire:

Enregistrer un commentaire