473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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

Jul 23 '05 #1
2 1614
On 22 Feb 2005 17:06:01 -0800, us****@sta.samsung.com wrote in
comp.lang.c++:
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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 23 '05 #2
On 22 Feb 2005 17:06:01 -0800, us****@sta.samsung.com wrote:
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]

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dom Gilligan | last post by:
Is there any way to get the preprocessor to produce the current line number in double quotes? At first sight, gcc seems to replace __LINE__ last (which would make sense), and so won't replace it at...
1
by: Spry | last post by:
Hi, I wanted to write macros for finding the number of memory allocations and deallocations also wanted to find the locations. The code I have is a pretty big one. I have a wrapper on top of...
5
by: Carlos | last post by:
I have a macro #define DIE(msg) do { fprintf(stderr, "%s (l.%d)\n", msg, __LINE__);\ exit(1); }\ while (0) and it works :). But later I thought, that if I use it like this: s =...
9
by: Francois Grieu | last post by:
Hello, I wrote this: #define M(x) enum { m##__LINE__ = x }; #line 1000 M(126) M(341) M(565) ...
7
by: Kenneth Brody | last post by:
Am I correct that using __FILE__ and __LINE__ within a macro will expand to the filename and line in which the macro is invoked, rather than where it is defined? For example, in a header file: ...
5
by: Generic Usenet Account | last post by:
Can someone kindly explain why stringification of the compiler preprocessor macro __LINE__ requires two steps, instead of one? I wanted to pass the error location of a system call to perror() and...
3
by: pistmaster | last post by:
Hi, I am trying the use the current line number in my logging and I want to stringify it so that I know the size of the buffer required to output the log string. I would have though I could use...
3
by: travis.downs | last post by:
Hi, I'm trying to use a macro to create a unique temporary variable name, such as #define TEMP_OBJ(string) MyType obj_ <some magic here(string); So something like TEMP_OBJ("foo")
4
by: Torsten Wiebesiek | last post by:
Hi, I have a problem with the preprocessor. I have written my own little assert macro. This is supposed to log a message (with log4cxx): #define LogAssert(Expression) \ if (Expression) { \...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.