Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get the current line number of a program?

0 views
Skip to first unread message

Sunny

unread,
Nov 20, 2001, 10:00:18 PM11/20/01
to
Hi :

Who know that how to get the current line number of a program? And which API
in C++ and C can implement this ?

Thanks


Scot T Brennecke

unread,
Nov 20, 2001, 10:21:21 PM11/20/01
to
__LINE__

Stefan Leifheit

unread,
Nov 21, 2001, 8:22:45 AM11/21/01
to
>.
>

Hi!

Actually, at runtime line numbers are of no meaning - all
that gets executed is the assembly generated by your C/C++
compiler. However, the C/C++ preprocessor inserts the
current line wherever you insert __LINE__ into your code.

Best regards
Stefan

David

unread,
Nov 22, 2001, 10:42:56 PM11/22/01
to
Sunny,

The line number should be generated in the compiling time. Therefore, we
may get it by some macros. If you want to retrieve the line number, you can
use the __LINE__ macro.

e.g.
printf("%d", __LINE__);

The macro for file names is __FILE__

Hope this help.

-Dave

0 new messages