Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

721 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