   how to add __FILE__ to assert
  I use many assert in code.but now when assert happen I do not know where is it.How to add extra info to show?   
  Why do you need it? When a program I have an assert in hits the assert and fails, I get the file and line number.   ;  Are you saying that your assert macro provides no information at all? At the very least it should, as Endar says, break at the correct line in you code. It should also display a filename and line number. Can I ask what operating system / compiler you are using.   ;  You try replacing it with your own version:#ifdef NDEBUG# define my_assert(exp)#else# define my_assert(exp) _my_assert(exp, #exp, __FILE__, __LINE__)#endifvoid _my_assert(bool exp_c, const char *exp_s, const char *file, unsigned line) { if(!exp_c) {  fprintf(stderr, "assertion failed: %s at %s:%u", exp_s, file, line);  abort(); }}Or perhaps redefine the regular assert macro. It does seem strange that it 's not reporting the file by itself though.   ;Quote:Original post by pauls_1979Are you saying that your assert macro provides no information at all? At the very least it should, as Endar says, break at the correct line in you code. It should also display a filename and line number. Can I ask what operating system / compiler you are using.Windows 2000 vs2003.net If assert fail ,it just pop a window and provide no line ,file name etc infomation .and click button it just exit debug.   ;Quote:Original post by luasitdownQuote:Original post by pauls_1979Are you saying that your assert macro provides no information at all? At the very least it should, as Endar says, break at the correct line in you code. It should also display a filename and line number. Can I ask what operating system / compiler you are using.Windows 2000 vs2003.net If assert fail ,it just pop a window and provide no line ,file name etc infomation .and click button it just exit debug.That's odd.. It's a windowed application (as opposed to a console application), right?Anyway, you could try tweaking the code above into popping up a message box instead.   ;Quote:Original post by luasitdownWindows 2000 vs2003.net If assert fail ,it just pop a window and provide no line ,file name etc infomation .and click button it just exit debug.I don't have vs2003 here (well not installed), but I know that in 2005 you just have to press "ignore" then "break" in the new dialog box, or something like that, then vs should break on the line the assert was triggered from. I think that vs2003 sends its assert information (line number, file etc.) to the standard output stream, which when having a console application is the console, when you have a Win32 application I think it isn't set by default, but you can set it manually if I remember right (so the output will go to a file, or whereever you want it).   ;  On the page below you can see my version of the assert.http://www.fs-games.com/FipS/fs_core.fsAssert.php   ;/****assert.h - define the assert macro**  Copyright (c) Microsoft Corporation. All rights reserved.**Purpose:*  Defines the assert(exp) macro.*  [ANSI/System V]**  [Public]*****/#if!defined(_WIN32)#error ERROR: Only Win32 target supported!#endif/* Define _CRTIMP */#ifndef _CRTIMP#ifdef  _DLL#define _CRTIMP __declspec(dllimport)#else   /* ndef _DLL */#define _CRTIMP#endif  /* _DLL */#endif  /* _CRTIMP *//* Define __cdecl for non-Microsoft compilers */#if( !defined(_MSC_VER) && !defined(__cdecl) )#define __cdecl#endif#undef  assert#ifdef  NDEBUG#define assert(exp)((void)0)#else#ifdef  __cplusplusextern "C" {#endif_CRTIMP void __cdecl _assert(const char *, const char *, unsigned);#ifdef  __cplusplus}#endif#define assert(exp) (void)( (exp) || (_assert(#exp, __FILE__, __LINE__), 0) )#endif  /* NDEBUG */which is assert define ,but why not show line or file name??just pop a window [Edited by - luasitdown on December 7, 2005 10:28:59 AM];  To add more information to assert, I do the following:assert(conditionX && "Function foo() failed on conditionX");When this assert fires, it will tell you the condition that fails along with the message you &&ed with it.   