Function redeclaration on C++ -
i have been reviewing implementation of tool , observed unusual.
#ifdef __gnuc__ #define variable_is_not_used __attribute__ ((unused)) #else #define variable_is_not_used #endif static variable_is_not_used void load_vertex_intervals(std::string base_filename, int nshards, std::vector<std::pair<vid_t, vid_t> > & intervals, bool allowfail); static variable_is_not_used void load_vertex_intervals(std::string base_filename, int nshards, std::vector<std::pair<vid_t, vid_t> > & intervals, bool allowfail=false) { std::string intervalsfilename = filename_intervals(base_filename, nshards); std::ifstream intervalsf(intervalsfilename.c_str()); if (!intervalsf.good()) { if (allowfail) return; // hack logstream(log_error) << "could not load intervals-file: " << intervalsfilename << std::endl; } assert(intervalsf.good()); intervals.clear(); vid_t st=0, en; for(int i=0; < nshards; i++) { assert(!intervalsf.eof()); intervalsf >> en; intervals.push_back(std::pair<vid_t,vid_t>(st, en)); st = en + 1; } for(int i=0; < nshards; i++) { logstream(log_info) << "shard: " << intervals[i].first << " - " << intervals[i].second << std::endl; } intervalsf.close(); } why declaration of function above implementation? use of this?
thanks in advance!
edit: posted code, instead of simplified example
the simplies example of when need use function lot of places:
static void fun(int x); static void f() { fun(5); } static void fun(int x) { cout<<"x = "<<x<<endl; } without declaration not compile because in f()::fun(5) call compiler not know function exists. declaration says (afaik called "prototype") function exists , defined somewhere (will checked after).
without prototype compiler error:
t.cpp: in function ‘void f()’: t.cpp:20:10: error: ‘fun’ not declared in scope upd: in code posted here declaration makes no sense @ all. in
static variable_is_not_used void load_vertex_intervals(std::string base_filename, int nshards, std::vector<std::pair<vid_t, vid_t> > & intervals, bool allowfail); static variable_is_not_used void load_vertex_intervals(std::string base_filename, int nshards, std::vector<std::pair<vid_t, vid_t> > & intervals, bool allowfail=false) { you may delete first line declaration.
Comments
Post a Comment