dimanche 4 décembre 2016

Prevent coder's error : make sure a function is referenced at least once in project

When I coded and designed a system (in a game), I am sure that certain functions of some certain systems is designed to be referenced at least one place. Otherwise, some coders 99% forgot something, and bad things will happen.

The word reference, I mean that the function is appeared, but I don't care whether it not be called at runtime. For example :-

int main(){
    if(false){
         f1();       //<--- This function is referenced
    }
    f2();           //<---  This function is referenced
    /* f3()*/       //<---  This function is not referenced
}

I don't care where it is refereed - it only have to appear in the project.

void f5(){ }
void f4(){  f5(); }  //<--- f4() is not referenced, but f5() is referenced
int main(){}

It might be similar to find all references in Visual Studio.

Question

To prevent coder's error (forget to refer), how can I assert that?

Example

This is closest to what I want :-

class System_Orange{
    public: void update_customForOrange(){  //It is non-static
        assert_that_this_function_is_referred_at_least_one_occurance;
        //^ I want something like this line
    }
};

If the function is not referenced, when build, it will throw error.

Aucun commentaire:

Enregistrer un commentaire