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
239 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
Comment Utility
__LINE__, __FUNCTION__, __FILE__

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

Author Comment

by:EmadGirgis
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

744 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

17 Experts available now in Live!

Get 1:1 Help Now