Can func get the lineno who call itself? (C/C++)
- by kingkai
Hi, I've a problem , as the following code discribe itself.
1 #include<stdlib.h>
2 #include<stdio.h>
3 void log()
4 {
5 printf("Log [Line:%d]\n",__LINE__);
6 }
7 int main()
8 {
9 log();
10 log();
11 }
The expected result is
Log [Line:9]
Log [Line:10]
But, the fact is
Log [Line:5]
Log [Line:5]
No surprising, LINE has been substituted at the pre-process stage as 5.
My Question is, how to design the log function to get the expected result?
Thanks!