473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

help with DUMP function

Hi,

I am tracing this c program and I know nothing about this x_DUMP code. Can somebody explain to me ? Thanks.
Expand|Select|Wrap|Line Numbers
  1. /* header */
  2. # include <stdlib.h>
  3. # if x _DUMP
  4. # include <stdio.h>
  5. # endif
  6.  
  7. /* functions */
  8.  
  9. void function_name (int something)
  10. {
  11.  
  12. # if x_DUMP
  13. printf(" this is function a ");
  14. fflush(stdout);
  15. #endif
  16.  
  17. printf("something");
  18. }
  19.  
  20. # if x_DUMP
  21. void x_dump( )
  22. {
  23.  
  24. printf("something");
  25. printf(" something");
  26.  
  27. fflush(stdout);
  28. }
  29.  
  30. # endif
Jul 2 '07 #1
5 4244
weaknessforcats
9,208 Expert Mod 8TB
The person who wrote this code did not know how to use a debugger. So instead, a bunch of printf() statements are spattered all over the application.

Now when you build, if you define x_DUMP, all those printf() will be part of the build. Then when the program is working you build again without defining x_DUMP and all the printf() are not part of the build.

The problem with this appraoch is that the program that tested with x_DUMP defined is not the same code with x_DUMP not defined. In effect, you release untested code.

Personally, I would rip all if the x_DUMP out of the code and start using a debugger.

Don't forget that you can also use asserts.
Jul 2 '07 #2
Thank you so much for the explanation. Actually each of separated functions contain more than 500 lines of codes. Maybe it is easier for us to trace either is is functioning or not with the x_DUMP. The problem now is I don't know how to invoke the x-DUMP in each function. What should I do?

Thank you.
Jul 2 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
You just need to define x_DUMP.


x_DUMP does not need to be a particular value.

#define x_DUMP

is all you need.

If there is a header file that is included in all of your course files you could put the #define in that header. It is preferable, though, to define x_DUMP on the command line of the compiler. That way, you don't have to remember to delete the #define and rebuild before releasing your code.

If you use Visual Studio.NET, you can define this in the project properties under C/C++ and the PreProcessor.

All this does is make the compiler command line contain -Dx_DUMP.

If you are not using Visual Studio, check out how to set preprocessor directives as property values.
Jul 2 '07 #4
Thank you so much. The x_DUMP already defined in the header file, x.h .

When I checked the header file , x.h , one of the line of code already defined x_DUMP as follow:

#define TTHEAP_DUMP 0

Roughly, 2 files involved: x.c and x.h

x.c call the x.h file.

coding in the x.c are as mentioned above , and the x.c also had #include <x.h>

In the x.h , it defined the x_DUMP , as #define TTHEAP_DUMP 0

There is no main function in the x.c

I don't know how to trace the program.
Jul 2 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
In the x.h , it defined the x_DUMP , as #define TTHEAP_DUMP 0
This defines TTHEAP_DUMP and not x_DUMP.

What, exactly, is the code in your x.h header?

If there is no main() in x.c, then x.c is part of a larger program. If you want to debug the code in x.c, you set a debugger breakpoint and wait for the path of execution to go into x.c where it will hit your breakpoint, stop, and drop you into your debugger. Then yoyu can step through the code.
Jul 3 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: KENNY L. CHEN | last post by:
I have a table with a CHAR column which stored a COBOL redefined record. I tried to retrieve part of the field from the column with Oracle substr function. Here is one of example: The...
1
by: WangKhar | last post by:
Hi (sorry this has turned into a bit of an epic...thought I'd as the experts!) SQL 2k, sp3a. Dual xeon 2.4. 2 gig ram. everything on a 3 disk raid 5. Microsoft SQL Server 2000 - 8.00.760...
2
by: D. Dante Lorenso | last post by:
First I created a function that selected the next available pin code from a table of pre-defined pin codes: CREATE FUNCTION "public"."get_next_pin_code" () RETURNS varchar AS' DECLARE...
2
by: Mike | last post by:
Greetings, Having a major problem here. running version 8.2 on win2003 server. The problem I am having is backing up a database seems to get to the last part of the backup and then fails. This...
5
by: NG | last post by:
Hi, We are having DB2-V7.2 DB on AIX 5.2 machine. Recently we upgraded our system to fixpack 13 and activated activate AIX asynchronous IO function. Our DB is going to crash recovery with...
9
by: tym | last post by:
HELP!!! I'm going round the twist with this... I have a VB6 application which is using DAO to access a database (Please - no lectures on ADO, I know what I'm doing with DAO!!) Ok, problem...
15
by: MLH | last post by:
In this forum, under a different subject title, I have explored the following: I want to examine each procedure in my class modules and standard modules (A97) Since the other subject title was...
26
by: Bail | last post by:
I will have a exam on the oncoming friday, my professor told us that it will base upon this program. i am having troubles understanding this program, for example what if i want to add all the...
4
by: wqyuwss | last post by:
Hi, We have several core dumps in our product. These core dump can be reproduced in the same place. That is system function call std::basic_istream<char,std::char_traits<char>>::getline. The...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.