Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 04-06-2004, 04:59 PM   #1
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, 05:08 PM   #2
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,545

Rep: Reputation: 160Reputation: 160
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, 09:15 PM   #3
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:

#include <stdio.h>

int main()

    printf("%s %i\n", __FILE__, __LINE__);
    return 0;
Old 04-07-2004, 07:54 AM   #4
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.


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 05:38 AM
mmm instruction help... Beppe83 Linux - Software 1 05-31-2004 07:57 AM
Finding out the location of my modem and scrol mice kobs Linux - Newbie 11 03-15-2004 05:03 AM
Illegal instruction madsjakob Linux - Software 0 10-28-2003 07:25 AM
Finding Device Driver Location and VERSIONS Rita Linux - Software 0 01-20-2002 08:20 AM

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

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