Mental Patient on Tue, 24 Sep 2002 16:50:17 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] [C QUESTION] how to tell caller of a function


On Tue, 2002-09-24 at 09:58, Bill Jonas wrote:
> On Tue, Sep 24, 2002 at 09:49:20AM -0400, Kevin Brosius wrote:
> > You can easily add printf() functions inside the code which print out
> > the function name, or variables inside the program.
> 
> Well, yes, but the problem is how a function can get the name of the
> function which is calling it so that you can print it in the first
> place.
> 
> To go back to the original question, why not modify the function
> slightly so that it takes an addtional char* argument and pass the name
> of the caller when it calls the function?  Seems like the least work to
> do what Fred's friend wants, unless there are dozens or hundreds of
> instances of the function in question being called.

Rather than munging the code, which depending on what it does, may be
undesireable, just break down and spend the 20 minutes learning ddd, gdb
or what have you. Google for howto set break points and how to use gdb.
You'll be better served later when you suddenly need to step line by
line through a function that for some reason is blowing up. Debuggers
aren't that hard to use. They're made for doing exactly this sort of
thing and knowing how to use one will make life so much nicer in the
future.

Just add a -g to your CFLAGS and run the program in ddd. Its got a nice
GUI, it wont be as 'hard' as gdb and you'll be better served for
learning how to really debug C. If you go the printf route, make sure
you're not buffered, or that's going to be the next part of this thread.
:)


-- 

Mental (Mental@NeverLight.com)

This body. This body holding me. Be my reminder here that 
I am not alone in
This body, this body holding me, feeling eternal
All this pain is an illusion.

--Tool "Parabola"

CARPE NOCTEM, QUAM MINIMUM CREDULA POSTERO.

GPG public key: http://www.neverlight.com/pas/Mental.asc


Attachment: signature.asc
Description: This is a digitally signed message part