473,378 Members | 1,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

__FILE__ and __LINE__

Neo
Hie,
Can I put __FILE__ and __LINE__ macros inside the class function which
may not be inline. And

void function()
{
classobject::LogInfo(...);
}

Internally LogInfo should log file name and line number. Here I dont
want user to pass those macros and also dont want to use any macros.
Is there any solution?

Nov 29 '06 #1
5 3341
On 2006-11-29 06:42, Neo wrote:
Hie,
Can I put __FILE__ and __LINE__ macros inside the class function which
may not be inline.
Since they are macros they are expanded by the pre-processor so whether
the functions are inline or not does not matter, it's the file and line
on which the code is written that is "returned", not where they are called.
And

void function()
{
classobject::LogInfo(...);
}

Internally LogInfo should log file name and line number. Here I dont
want user to pass those macros and also dont want to use any macros.
Is there any solution?
Do I understand you correctly in not wanting to pass the file and line
to the LogInfo()-function but would rather like it to know the line and
file magically in some way? Might work, depending on which filename and
line-number you want, as I said earlier, it's the filename and line-
number of the file where the code is written that is expanded.

--
Erik Wikström
Nov 29 '06 #2
Neo
What you wrote is correct. So is there any way to do it?

Erik Wikström wrote:
On 2006-11-29 06:42, Neo wrote:
Hie,
Can I put __FILE__ and __LINE__ macros inside the class function which
may not be inline.

Since they are macros they are expanded by the pre-processor so whether
the functions are inline or not does not matter, it's the file and line
on which the code is written that is "returned", not where they are called.
And

void function()
{
classobject::LogInfo(...);
}

Internally LogInfo should log file name and line number. Here I dont
want user to pass those macros and also dont want to use any macros.
Is there any solution?

Do I understand you correctly in not wanting to pass the file and line
to the LogInfo()-function but would rather like it to know the line and
file magically in some way? Might work, depending on which filename and
line-number you want, as I said earlier, it's the filename and line-
number of the file where the code is written that is expanded.

--
Erik Wikström
Nov 29 '06 #3
Neo
What you wrote is correct. So is there any way to do it?

Erik Wikström wrote:
On 2006-11-29 06:42, Neo wrote:
Hie,
Can I put __FILE__ and __LINE__ macros inside the class function which
may not be inline.

Since they are macros they are expanded by the pre-processor so whether
the functions are inline or not does not matter, it's the file and line
on which the code is written that is "returned", not where they are called.
And

void function()
{
classobject::LogInfo(...);
}

Internally LogInfo should log file name and line number. Here I dont
want user to pass those macros and also dont want to use any macros.
Is there any solution?

Do I understand you correctly in not wanting to pass the file and line
to the LogInfo()-function but would rather like it to know the line and
file magically in some way? Might work, depending on which filename and
line-number you want, as I said earlier, it's the filename and line-
number of the file where the code is written that is expanded.

--
Erik Wikström
Nov 29 '06 #4
Neo wrote:
>
Erik Wikström wrote:
On 2006-11-29 06:42, Neo wrote:
Hie,
Can I put __FILE__ and __LINE__ macros inside the class function which
may not be inline.
Since they are macros they are expanded by the pre-processor so whether
the functions are inline or not does not matter, it's the file and line
on which the code is written that is "returned", not where they are called.
And
>
void function()
{
classobject::LogInfo(...);
}
>
Internally LogInfo should log file name and line number. Here I dont
want user to pass those macros and also dont want to use any macros.
Is there any solution?
Do I understand you correctly in not wanting to pass the file and line
to the LogInfo()-function but would rather like it to know the line and
file magically in some way? Might work, depending on which filename and
line-number you want, as I said earlier, it's the filename and line-
number of the file where the code is written that is expanded.
What you wrote is correct. So is there any way to do it?
<don't top-post please>

What he meant is if you put the macros in the LogInfo function, like

struct classobject
{
void LogInfo(char const * msg)
{
somefilestream << __FILE__<<":"<<__LINE__<<msg;
}
};

It will always print the same __FILE__ (one where classobject is
defined) and the same __LINE__( that is, the one above)

You need to make LogInfo to take additional two parameters, a filename
and a line number

void LogInfo(char const *file, int line, char const * msg)
{
somefilestream << file <<":"<<line<<msg;
}

and a macro

#define LOGINFO(X) classobject::LogInfo(__FILE__, __LINE__, X)

and use that instead

Nov 29 '06 #5
Neo wrote:
What you wrote is correct. So is there any way to do it?
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
Nov 29 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Spry | last post by:
Hi, I wanted to write macros for finding the number of memory allocations and deallocations also wanted to find the locations. The code I have is a pretty big one. I have a wrapper on top of...
9
by: qazmlp | last post by:
How exactly __FILE__ and __LINE__ macros are defined? Or, Is the definition of these macros implementation dependent ? I am wondering how easily they can get the file name and line number...
5
by: jake1138 | last post by:
I couldn't find an example of this anywhere so I post it in the hope that someone finds it useful. I believe this is compiler specific (I'm using gcc), as C99 defines __VA_ARGS__. Comments are...
5
by: baumann.Pan | last post by:
where are these macros defined? can I use it a release ver code?
7
by: Kenneth Brody | last post by:
Am I correct that using __FILE__ and __LINE__ within a macro will expand to the filename and line in which the macro is invoked, rather than where it is defined? For example, in a header file: ...
1
by: cbro | last post by:
Is there a C# equivalent for the C++ macros __FILE__ and __LINE__ ? They are quite handy for pinpointing where an event log entry was generated. I am using Visual Studio.NET 2003.
5
by: PengYu.UT | last post by:
Hi, I want to print out error message from all the three macros __FILE__, __LINE__, __PRETTY_FUNCTION__. I'm wondering if there is one macro which serves equivalently as the combinations of the...
9
by: Neo | last post by:
Hi Friends, I am planning to use "__FILE__,__LINE__,__FUNCTION__ " for a logging component in my class. In debug build I gets all information. I tried with release mode also and it works. But I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.