jeudi 27 août 2015

Creating incrementing integer values for each file

I am working on program which generates error codes per file. Error codes need to start from zero and increment onwards, a file can contain 'n' error codes.

I tried with COUNTER macro but it seems it is not working per file basis and is being incremented globally.

If there a way I can reset COUNTER to zero for each file?

// a.cpp
int a_error1 = GetErrorCode(); // error1 = 0
int a_error2 = GetErrorCode(); // error2 = 1
int a_error3 = GetErrorCode(); // error3 = 2
int a_error4 = GetErrorCode(); // error4 = 3

Similarly

// b.cpp
int b_error1 = GetErrorCode(); // error1 = 0
int b_error2 = GetErrorCode(); // error2 = 1
int b_error3 = GetErrorCode(); // error3 = 2
int b_error4 = GetErrorCode(); // error4 = 3

I do not want to have something like

// a.cpp
int a_error1 = 0 
int a_error2 = 1 
int a_error3 = 2 
int a_error4 = 3 

As this is error prone and can contain duplicate values.

Aucun commentaire:

Enregistrer un commentaire