system call to return current line number 
Author Message
 system call to return current line number

Date: 13 Sep 1994 13:44:17 -0400

> For example, consider the following piece of code:

> main()
> {
>  printf("line number = %i\n",linenum());
>  printf("line number = %i\n",linenum());
> }

> The first linenum() should return 3 while second 4,assuming main() is
> starting from the first line.

The best way I can think of that will work the way you are using it and
produce the results you desire would be:

#include <stdio.h>

#define linenum() ((int) __LINE__)
#line 1
int main (void)
  printf ("line number = %i\n", linenum ());
  printf ("line number = %i\n", linenum ());

  return (0);


It won't count the include file or the define statement as lines in your
program, hence it will produce the output of 3 and 4 for the 2 printf's
yet still be ANSI C.

|Fidonet:  Jonas Schlein 2:201/2137.1

| Standard disclaimer: The views of this user are strictly his own.

Sun, 02 Mar 1997 04:44:17 GMT  
 [ 1 post ] 

 Relevant Pages 

1. system call to return current line number

2. system call to return current line number

3. How to get current line number??

4. Bug: Textbox.Lines.Length returns an incorrect number

5. Calling Fortran-functions returning complex numbers from C

6. printing line number of calling function ?

7. call system() in linux return code = 2560

8. Q: Return-values of system("...") calls

9. Help: C system call that returns list of all processes in Unix

10. API call to return a specific machines system clock

11. LINE -- Line Number Pipe for MS-DOS

12. LINE -- Line Number Pipe


Powered by phpBB® Forum Software