LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-06-2004, 05:59 PM   #1
iftiuk
Member
 
Registered: Apr 2004
Location: Washington DC
Posts: 43

Rep: Reputation: 15
Finding the execution location of a instruction


Suppose I have a file myfile.c and in it at line 70 I have a printf statement and another at line 50 and another at somewhere else may be in a different file. Now whenever these printf are executed is there any way to know from which file and from what line these were issued? Did I make sense?
 
Old 04-06-2004, 06:08 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,540

Rep: Reputation: 149Reputation: 149
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

It is possible to know it. But how would you like to use it? If you'd like to write a different code for a different place it was executed from it's not easy, but for debigging purposes it's very easy (in gdb there's 'bt' option that shows you a trace of functions run before the current one).
 
Old 04-06-2004, 10:15 PM   #3
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
You might also be looking for the predefined macros __FILE__ and __LINE__.

For instance:

Code:
#include <stdio.h>

int main()
{

    printf("%s %i\n", __FILE__, __LINE__);
    return 0;
}
 
Old 04-07-2004, 08:54 AM   #4
iftiuk
Member
 
Registered: Apr 2004
Location: Washington DC
Posts: 43

Original Poster
Rep: Reputation: 15
Thank you. I did not realize we had these macros in C.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what does this instruction mean sibtay Programming 2 08-17-2004 06:38 AM
mmm instruction help... Beppe83 Linux - Software 1 05-31-2004 08:57 AM
Finding out the location of my modem and scrol mice kobs Linux - Newbie 11 03-15-2004 06:03 AM
Illegal instruction madsjakob Linux - Software 0 10-28-2003 08:25 AM
Finding Device Driver Location and VERSIONS Rita Linux - Software 0 01-20-2002 09:20 AM


All times are GMT -5. The time now is 09:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration