473,385 Members | 1,185 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,385 software developers and data experts.

Stack Pointer..?

Hi people...

Here's my question...

a function other than main is getting executed
you have to find out which function called this function

how can we do in C...?

Nov 15 '05 #1
8 3334
In article <11*********************@f14g2000cwb.googlegroups. com>,
<7t*******@gmail.com> wrote:
:Here's my question...

:a function other than main is getting executed
:you have to find out which function called this function

:how can we do in C...?

You can't do your homework in portable C.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
Nov 15 '05 #2

<7t*******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi people...

Here's my question...

a function other than main is getting executed
you have to find out which function called this function

how can we do in C...?


Use a debugger and breakpoints? Or is this an academic question.
Nov 15 '05 #3

7t*******@gmail.com wrote:
Hi people...

Here's my question...

a function other than main is getting executed
you have to find out which function called this function

how can we do in C...?


I believe using __FUNCTION__ will show the current function's name, I'm
not sure about showing the calling function's name. My best advice,
try searching the groups for __FUNCTION__ to see if this question, or a
similar one, has already been answered.

Nov 15 '05 #4
ma************@gmail.com wrote:
7t*******@gmail.com wrote:

Hi people...

Here's my question...

a function other than main is getting executed
you have to find out which function called this function

how can we do in C...?


I believe using __FUNCTION__ will show the current function's name, I'm
not sure about showing the calling function's name. My best advice,
try searching the groups for __FUNCTION__ to see if this question, or a
similar one, has already been answered.

Are you using gcc? If so you can get access to the frames, which will
help you figure out how you got to where you are.

Nov 15 '05 #5
7t*******@gmail.com wrote:
: Hi people...

: Here's my question...

: a function other than main is getting executed
: you have to find out which function called this function

: how can we do in C...?

You could rewrite your functions to include that information

(No pretense of being real code)

main()
{
do_something("from main",1,2,3);
}

do_something( char *from, int i, int j, int k)
{
do_something_else("do_something",'a','b','c');
}

do_something_else( char *from, etc...)
{
printf("I was called from %s",from);
}
To get a full stack trace you would have to add some kind of link as well,
but I haven't thought to add that here.

Various compilers and debuggers have options to help do this sort of thing
much easier.

--

This programmer available for rent.
Nov 15 '05 #6
On 10 Oct 2005 11:48:02 -0700, ma************@gmail.com wrote in
comp.lang.c:

7t*******@gmail.com wrote:
Hi people...

Here's my question...

a function other than main is getting executed
you have to find out which function called this function

how can we do in C...?


I believe using __FUNCTION__ will show the current function's name, I'm
not sure about showing the calling function's name. My best advice,
try searching the groups for __FUNCTION__ to see if this question, or a
similar one, has already been answered.


Unfortunately, this isn't anything in the standard C language.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 15 '05 #7
7t*******@gmail.com writes:
a function other than main is getting executed
you have to find out which function called this function


If there's a specific function that wants to know this, then you
might be able to rig something up with a macro, e.g.
#define function(arg1, arg2) real_function(arg1, arg2, __func__)

...

void real_function(int arg1, void *arg2, const char *calling_function)
{
...
}
There is no portable, general solution.
--
"Am I missing something?"
--Dan Pop
Nov 15 '05 #8
On 10 Oct 2005 13:28:52 -0700, yf***@vtn1.victoria.tc.ca (Malcolm
Dew-Jones) wrote:
7t*******@gmail.com wrote:
: Hi people...

: Here's my question...

: a function other than main is getting executed
: you have to find out which function called this function

: how can we do in C...?

You could rewrite your functions to include that information <snip: added 'from' parameter to every function and call> To get a full stack trace you would have to add some kind of link as well,
but I haven't thought to add that here.

Various compilers and debuggers have options to help do this sort of thing
much easier.


To be clear: compilers and debuggers (usually) have options to trace
back the calling stack or equivalent. None that I know of do this by
the mechanism of adding a special from_name parameter.
- David.Thompson1 at worldnet.att.net
Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: news.tkdsoftware.com | last post by:
Aside from comp.compilers, is there any other forum, newsgroup or medium where I can post questions concerning the development of a byte code compiler & virtual stack machine? --
20
by: Sushil | last post by:
Hi gurus I was reading FAQ "alloca cannot be written portably, and is difficult to implement on machines without a conventional stack." I understand that the standard does not mandate...
5
by: Adrian | last post by:
Is there a way (understandably non-portable) to get the call stack from within a function? That is, assuming the application has been compiled with symbols, get the list of calling function names...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
16
by: sarathy | last post by:
Hi all, I need a few clarifications regarding memory allocaion in C++. I apologize for the lengthy explanation. 1. In C++, Objects are allocated in heap. What does heap refer to? Is it an area...
24
by: John | last post by:
I know this is a very fundamental question. I am still quite confused if the program call stack stack should always grows upwards from the bottom, or the opposite, or doesn't matter?? That means...
7
by: Dougan | last post by:
I've seen code that allocates an object on the stack and then saves a class reference to it. example: void ScribbleArea::resizeImage( const QSize &newSize) { QImage newImage( newSize, );...
4
by: code break | last post by:
Hi all, What is the difference between stack pointer and frame pointer ? Any suggestions are welcome ,,,
9
by: coder_lol | last post by:
Thanks everybody for helping me with the Syntax confusion! The implicit conversion stuff really got me :) I have one more question... Array<int32ia; Does the above use the default...
9
by: Tarique | last post by:
Hello all.I am trying to implement a stack which can store either integer or float values. The code is given below: #include<stdio.h> #include<stdlib.h> #include<string.h> #define...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.