__FILE__ and __LINE__

N

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?
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

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.
 
D

dasjotre

Neo said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top