?
Solved

Using _LINE_ and _FILE_ macros

Posted on 2003-03-06
4
Medium Priority
?
1,176 Views
Last Modified: 2010-10-05
I was trying to compile the following program:

#include <stdio.h>

main()
{

printf("\n This print is from line %d of file %s",_LINE_,_FILE_);

}

I do gcc test.c (name of the program file) and the compiler says that _LINE_ and _FILE_ are undeclared.

Is there a way to make this work or is this compiler dependent?

Regards,
Arut
0
Comment
Question by:arut
[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
4 Comments
 
LVL 6

Accepted Solution

by:
marconovaro earned 300 total points
ID: 8079608

I think that the correct definition is:

__LINE__
__FILE__

(double underscore)

M
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 8079641
Why are you trying to use those macros. What is your purpose...
0
 
LVL 6

Expert Comment

by:gj62
ID: 8080658
arut -

marconovaro is right, it is double-underscore for each.  He should get the points...

rajeev -

those macros give the source code filename and the source code line number.  They are ANSI predefined macros and are commonly used to report errors/status when you can't run in a debugger.

0
 
LVL 8

Expert Comment

by:akshayxx
ID: 8085312
i also support macronovaro.. and
just to add to your knowledge ..( pardon me if u already know this)..
__FUNCTION__ gives u function name
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

801 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