c++ - Gettin line number of the called function -


please let me know if can or not?

i writing library work track memory allocation , de-allocation in c++. in short, trying see if application not have memory leaks. did far.

overrode new , delete operator , now. whenever application uses new, planning store address , number of bytes allocated in call. similarly, when delete called on address, remove stored list. until fine. want store file name , line number "new" called. can in overridden new. there way line number in overridden function?


1    int main() 2    { 3       // say, structure 4        *a = new a(); 5        return 0; 6     } 7    void* operator new( size ) 8    { 9        // 10       // store line number , file name on line 4 ??? can it? 11       return (malloc(size)); 12   } ------------------------ 

the macros __line__ gives line number __function__ , __file__ helpful, giving const char* of enclosing function, , file name. edit: (__function__ not standard supported several compilers) unfortunately these macros take value in place. not possible ask caller.

you should write __line__ , __file__ macros everywhere use new. :(.

or... can have access stack of callers, don't know of common ways that... , had searched long think not possible if not in debug mode.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -