Different behavior from __LINE__ macro in g++ 2.95.x and 3.x

U

usenet

On g++ version 3.X I get the "wrong" line number, 8 reported
for the following code:

1 #include <iostream>
2 using namespace std;
3 int main(void)
4 {
5 ^M^M^Mcout << "file:" << __FILE__ << " line:" << __LINE__ << endl;
6 }
7 /*
8 3 ^Ms on cout line 5 code reports
9 file:wrongLine.C line:8
10 */

where ^M denotes control-M.

Does this conform to standard? 2.95.x version's I've tried
"correctly" report 5.

Thanks in advance for your reply.

Gary
 
J

Jack Klein

On g++ version 3.X I get the "wrong" line number, 8 reported
for the following code:

1 #include <iostream>
2 using namespace std;
3 int main(void)
4 {
5 ^M^M^Mcout << "file:" << __FILE__ << " line:" << __LINE__ << endl;
6 }
7 /*
8 3 ^Ms on cout line 5 code reports
9 file:wrongLine.C line:8
10 */

where ^M denotes control-M.

Does this conform to standard? 2.95.x version's I've tried
"correctly" report 5.

Thanks in advance for your reply.

Gary

Since the code sample you posted has illegal characters in it, the C++
language does not specify the behavior.
 
R

Raymond Martineau

On g++ version 3.X I get the "wrong" line number, 8 reported
for the following code:

1 #include <iostream>
2 using namespace std;
3 int main(void)
4 {
5 ^M^M^Mcout << "file:" << __FILE__ << " line:" << __LINE__ << endl;
6 }
7 /*
8 3 ^Ms on cout line 5 code reports
9 file:wrongLine.C line:8
10 */

where ^M denotes control-M.

Does this conform to standard? 2.95.x version's I've tried
"correctly" report 5.

[semi-ot for CLC]
'^M' is one of the characters used to denote a newline. Two other
combinations can be '^J' and the '^M^J' pair.

The actual newline information used is system-dependant. In this case, it
looks like G++ is attempting to intellegently detect which newline is in
use (Dos/Unix compatability), causing the difference between Line numbers.
[/ot]
 

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,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top