[LCP]debugging?

Bill Rausch BRausch at owt.com
Mon Feb 7 13:17:01 UTC 2005


What goes in a .h file is called a prototype. It tells the compiler 
how to call the routine.  Then in a .c file you write the actual 
function.

e.g.:

.h file contains:
    int myfunc( double abc );

.c file contains:

    int myfunc( double abc )
    {
       return (int)(abc * 2);
    }

A stub version of the function would be to write something like:

    int myfunc( double abc )
    {
       return 1;
    }

in the .c file. You just have a very simple function that returns a 
known value so you can get on with testing the program that calls 
myfunc(). Obviously stubs are more useful when developing complex 
functions.

 From your questions, I think you really should sit down with a 
textbook on C and work your way through it from one end to the other, 
then do the same with a Linux or Unix textbook.  Then come back here 
and ask more questions.

Bill

At 23:20 -0500 2/6/05, Zachary Uram wrote:
>On Sun, 6 Feb 2005 17:11:27 -0800, Bill Rausch <BRausch at owt.com> wrote:
>>
>>  Stub is a replacement function that you use to test a program. For
>>  example, if a program calls a function that does lots of complex
>>  stuff, you could replace the function with something really simple
>>  that takes the same parameters but skips the calculation. This allows
>>  you to test the calling routine without worrying about the details of
>>  the called function.
>
>Hi Bill,
>
>I see. Can I put a function's stub in a .h file? Sometimes I see
>functions defined after main and they have no stub before main. How do
>I determine if I need a stub or not?
>
>>  Segmentation fault is almost always a bad pointer or bad parameter
>>  passed to a function.  For example, you malloc some space for a
>>  pointer x, later you free it, and then even later you use x as though
>>  you hadn't freed it. It will compile ok, and might even run ok most
>>  of the time but once in a while you'll get in trouble because once
>>  you've freed it you are never supposed to refer to it again until you
>>  malloc some new space.
>
>Oh, could you perhaps give some code snippets to document these error
>conditions and how to fix them?
>
>Regards!
>Zach


-- 
Bill Rausch

The best things in life are nearest: Breath in your nostrils, light in your
eyes, flowers at your feet, duties at your hand, the path of right just
before you. -Robert Louis Stevenson, novelist, essayist, and poet
(1850-1894)




More information about the linuxCprogramming mailing list