Solved

In C++, I need a macro that builds a string that includes the file and the line number..

Posted on 2008-06-16
3
251 Views
Last Modified: 2010-04-01
C++, Linux

as part of my effort to understand an application I have, I need to build a macro that automatically builds a string with the file number and the line number.
I can print that string that will show me the execution path.
I am going to add this Macro in places and print the output!
0
Comment
Question by:EmadGirgis
  • 2
3 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 21795157
__LINE__, __FUNCTION__, __FILE__

#define LOG_HERE printf("%s %s %d\n",__FILE__,__FUNCTION__,__LINE__)
0
 

Author Comment

by:EmadGirgis
ID: 21795272
Thank you very much...
I need to advance this so it would generate me a string to pass to other function!!

So I mean
string S
S would be equal to
("%s %s %d\n",__FILE__,__FUNCTION__,__LINE__)
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 21795317
The format specifiers work only with printf family of functions ... to for a string, use sprintf

sprintf (mystring, "%s %s %d\n",__FILE__,__FUNCTION__,__LINE__);

Note ... snprintf is safer than printf .. make sure mystring has sufficient memory
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now