can somebody give me an example of a DEBUG program...I have to create my own DEBUG mode........I know what that thing do....but I dunno what it really looks like
i just have the idea that i can use
any idea????Code:#ifdef DEBUG ....... #endif
can somebody give me an example of a DEBUG program...I have to create my own DEBUG mode........I know what that thing do....but I dunno what it really looks like
i just have the idea that i can use
any idea????Code:#ifdef DEBUG ....... #endif
Code:int function(void){ #ifdef DEBUG printf("function001() called\n"); #endif ... ... return 0; }
btw...what the meaning of that "......" kinda thing???
ym id >>>>> asmahmazlan
it means the rest of the code...
When no one helps you out. Call google();
then...what the command line suppose to looks like?? i'm currently using Borland 5.5 compiler....
ym id >>>>> asmahmazlan
Here's one way:
Code:#include <stdio.h> void foo(void) { #ifdef DEBUG fprintf (stderr, "DEBUG: Entering function foo()\n"); #endif } int main(void) { foo(); return(0); } >bcc32 -DDEBUG junk1.c >junk1 DEBUG: Entering function foo() >bcc32 junk1.c >junk1 (no output from program this time)
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
thanks guys..that's really help..
ahha....now I can produce an error message for myself (that kinda thing that alwiz appear ,makes us very mad sometimes .... ) ...just to share something.......
and then when i type in the command lines, i've got something like thisCode:#include <stdio.h> main() { #ifdef DEBUG fprintf(stderr,"Error %s %d :There's a bug in this line!!\n",__FILE__,__LINE__); #else printf("Can't find any bug though!!!\n"); #endif return 0; }
hope that anyone else who're also working on this thing find it somewhat useful..Code:C:\Borland\bcc55\Bin>bcc32 -DDEBUG debug.c Borland C++ 5.5 for Win32 Copyright (c) 1993, 2000 Borland debug.c: Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland C:\Borland\bcc55\Bin>debug Error debug.c 6 :There's a bug in this line!! C:\Borland\bcc55\Bin>bcc32 debug.c Borland C++ 5.5 for Win32 Copyright (c) 1993, 2000 Borland debug.c: Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland C:\Borland\bcc55\Bin>debug Can't find any bug though!!!
ym id >>>>> asmahmazlan
Thats a debug message, I guess, you compile it in ir not - not very useful, but a more useful "debug mode" would be to:
Code:#include <... int DEBUG = 0; // or false int main ( int argc, char **argv ) { char *progname; ... progname = *argv++; if (!strcmp(*argv,"-d") { argv++; DEBUG = 1; // or true } .... handle rest of arguments .... ... if (DEBUG) printf("Program %s started.\n",progname); .... more program .... if (DEBUG) printf("Program %s ended.\n",progname); } void functionOne ( int arg ) { if (DEBUG) printf("Entering functionOne(%d)\n",arg); ... } int functionTwo ( int argi, char *argc ) { if (DEBUG) printf("Entering functionTwo(%d,%s)\n",argi,argc); ... if (DEBUG) printf(" did this!\n"); ... if (DEBUG) printf(" did that with result %d!\n",result); ... } ... etc.
This does not mean there is a bug in the program. Basically if you program is not running properly then you want to c ompile and run it in DEBUG mode so that you can see what your program is doing.Code:#include <stdio.h> main() { #ifdef DEBUG fprintf(stderr,"Error %s %d :There's a bug in this line!!\n",__FILE__,__LINE__); #else printf("Can't find any bug though!!!\n"); #endif return 0; }
Like hammer posted
If DEBUG is defined then you will know when this function is called. It does not mean there is a bug in the code.Code:void foo(void) { #ifdef DEBUG fprintf (stderr, "DEBUG: Entering function foo()\n"); #endif }
hmmm....I'm still quite confuse...what is actually the function of this "debug" command??is it to indicate what the program is doing at each stage or only at a particular stage??
Last edited by myer_784; 03-14-2005 at 11:13 AM.
ym id >>>>> asmahmazlan
>>what is actually the function of this "debug" command
You output what messages you think are necessary to help you solve problems. Sometimes, you might need to know what functions have been invoked and in what order; sometimes you may need to know the value of a particular variable at a given time. These are only basic examples, you can make it as simple or complex as you like.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
If your program has crashed before foo() has been called you wouldnt get the msg. That is how you can narrow down where your bug may be.
what if I have both multiple files and this debug message at the same time??...in using the " -DDEBUG " command in the compilation process before running the program,what the command line suppose to be??...
this is the sample of the make file..usually we will have to type in the command as bcc32 -DDEBUG main.c......but this time I have all these combined files.....what file name should i use??? (say the name of this makefile is "MakeFile.txt" ...)Code:CC=bcc32 HEADERS=headers.h silly.exe: main.obj fun_a.obj fun_b.obj fun_c.obj $(CC) -esilly.exe main.obj fun_a.obj fun_b.obj fun_c.obj main.obj: $(HEADERS) main.c $(CC) -I. -c main.c fun_a.obj: $(HEADERS) fun_a.c $(CC) -I. -c fun_a.c fun_b.obj: $(HEADERS) fun_b.c fun_c.obj $(CC) -I. -c fun_b.c fun_c.obj: $(HEADERS) fun_c.c $(CC) -I. -c fun_c.c clean: del silly *.obj *.tds tidy: del *.tds
Last edited by myer_784; 03-16-2005 at 01:05 AM.
ym id >>>>> asmahmazlan