__LINE__ gives wrong number

View: New views
3 Messages — Rating Filter:   Alert me  

__LINE__ gives wrong number

by bin liu-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

The __LINE__ sometimes gives wrong number. To reproduce, run following program:

--------begin of file gsm.cpp--------------
#include <stdio.h> //line 1

int main(int argc, char **argv) //line 3
{
    srand((unsigned)time( NULL ));
    int i, j, k;

    char *foo[] = {"3F00"};
    char *bar[] = {"7F107F202FE2"};
    printf("k is %d\n", k = (rand()%2));
    for (i=0; i<sizeof(foo)/sizeof(foo[0]); i++){
        for (j=0; j<strlen(bar[i])/4; j++){
            if (k) //if k=0, the __LINE__ at line 17 becomes 14, if k=1, it is 16
                printf("");
        }
    }
    printf("line %d\n", __LINE__); //line 17

    return 0;
}

--------end of file gsm.cpp--------------

C:\cint>cint gsm.cpp
k is 0
line 14

C:\cint>cint gsm.cpp
k is 1
line 16

I encounter the issue with CINT v5.16.25 (checkout from cvs using tag v5-16-25) compiled by MSVC7 (Toolkit2003), note that v5.16.24 is without the issue.
 
I just tried latest v5.16.27, also has the issue.


Thanks & Regards,
Liu Bin


Parent Message unknown Re: __LINE__ gives wrong number

by bin liu-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Axel,

The problem (__LINE__ sometimes gives wrong number) still exist with latest v5.16.28 on both Windows (msvc7) and Linux (Ubuntu).

I said "that v5.16.24 is without the issue.", it was wrong. Even if this sample (gsm.cpp) gives correct number with v5.16.24 but other complex programs may also give wrong number with v5.16.24.

Workaround is, invoke __LINE__ inside 'for' loop like:
--------begin of file gsm.cpp--------------
#include <stdio.h> //line 1

int main(int argc, char **argv) //line 3
{
    srand((unsigned)time( NULL ));
    int i, j, k;

    char *foo[] = {"3F00"};
    char *bar[] = {"7F107F202FE2"};
    printf("k is %d\n", k = (rand()%2));
    for (i=0; i<sizeof(foo)/sizeof(foo[0]); i++){
        for (j=0; j<strlen(bar[i])/4; j++){ __LINE__; //<---- workaround
            if (k)
                printf("");
        }
    }
    printf("line %d\n", __LINE__); //line 17

    return 0;
}
--------end of file gsm.cpp--------------

So far the workaround works fine, so it is not urgent to fix if you are still busy on restructuring CINT :-).

Merry Christmas and Happy New Year!

Best regards,
liubin

2007/11/7, Axel Naumann <Axel.Naumann@...>:
Hi,

thanks for reporting this! I will probably fix it only after Dec 15,
though - we are very busy with restructuring CINT at the moment.

Cheers, Axel.

bin liu wrote:

> Hi,
>
> The __LINE__ sometimes gives wrong number. To reproduce, run following
> program:
>
> --------begin of file gsm.cpp--------------
> #include <stdio.h> //line 1
>
> int main(int argc, char **argv) //line 3
> {
>     srand((unsigned)time( NULL ));
>     int i, j, k;
>
>     char *foo[] = {"3F00"};
>     char *bar[] = {"7F107F202FE2"};
>     printf("k is %d\n", k = (rand()%2));
>     for (i=0; i<sizeof(foo)/sizeof(foo[0]); i++){
>         for (j=0; j<strlen(bar[i])/4; j++){
>             if (k) //if k=0, the __LINE__ at line 17 becomes 14, if k=1,
> it is 16
>                 printf("");
>         }
>     }
>     printf("line %d\n", __LINE__); //line 17
>
>     return 0;
> }
> --------end of file gsm.cpp--------------
>
> C:\cint>cint gsm.cpp
> k is 0
> line 14

>
> C:\cint>cint gsm.cpp
> k is 1
> line 16
>
> I encounter the issue with CINT v5.16.25 (checkout from cvs using tag
> v5-16-25) compiled by MSVC7 (Toolkit2003), note that v5.16.24 is without
> the issue.
>
>
>
> I just tried latest v5.16.27, also has the issue.
>
>
> Thanks & Regards,
> Liu Bin
>


Re: __LINE__ gives wrong number

by Axel Naumann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi liubin,

> So far the workaround works fine, so it is not urgent to fix if you
> are still busy on restructuring CINT :-).

it's still on the to-do list, and we are still busy with the new CINT.
It's good to hear the problem also existed with older versions - this is
what I expected.

> Merry Christmas and Happy New Year!

Same to you, if it's relevant for you :-)

Cheers, Axel.

On 2007-12-20 12:12, bin liu wrote:

> Hi Axel,
>
> The problem (__LINE__ sometimes gives wrong number) still exist with
> latest v5.16.28 on both Windows (msvc7) and Linux (Ubuntu).
>
> I said "that v5.16.24 is without the issue.", it was wrong. Even if
> this sample (gsm.cpp) gives correct number with v5.16.24 but other
> complex programs may also give wrong number with v5.16.24.
>
> Workaround is, invoke __LINE__ inside 'for' loop like: --------begin
> of file gsm.cpp-------------- #include <stdio.h> //line 1
>
> int main(int argc, char **argv) //line 3 { srand((unsigned)time( NULL
> )); int i, j, k;
>
> char *foo[] = {"3F00"}; char *bar[] = {"7F107F202FE2"}; printf("k is
> %d\n", k = (rand()%2)); for (i=0; i<sizeof(foo)/sizeof(foo[0]); i++){
>  for (j=0; j<strlen(bar[i])/4; j++){ __LINE__; //<---- workaround if
> (k) printf(""); } } printf("line %d\n", __LINE__); //line 17
>
> return 0; } --------end of file gsm.cpp--------------
>
> So far the workaround works fine, so it is not urgent to fix if you
> are still busy on restructuring CINT :-).
>
> Merry Christmas and Happy New Year!
>
> Best regards, liubin
>
> 2007/11/7, Axel Naumann <Axel.Naumann@...
> <mailto:Axel.Naumann@...>>:
>
> Hi,
>
> thanks for reporting this! I will probably fix it only after Dec 15,
> though - we are very busy with restructuring CINT at the moment.
>
> Cheers, Axel.
>
> bin liu wrote:
>> Hi,
>>
>> The __LINE__ sometimes gives wrong number. To reproduce, run
> following
>> program:
>>
>> --------begin of file gsm.cpp-------------- #include <stdio.h>
>> //line 1
>>
>> int main(int argc, char **argv) //line 3 { srand((unsigned)time(
>> NULL )); int i, j, k;
>>
>> char *foo[] = {"3F00"}; char *bar[] = {"7F107F202FE2"}; printf("k
>> is %d\n", k = (rand()%2)); for (i=0; i<sizeof(foo)/sizeof(foo[0]);
>> i++){ for (j=0; j<strlen(bar[i])/4; j++){ if (k) //if k=0, the
>> __LINE__ at line 17 becomes 14,
> if k=1,
>> it is 16 printf(""); } } printf("line %d\n", __LINE__); //line 17
>>
>> return 0; } --------end of file gsm.cpp--------------
>>
>> C:\cint>cint gsm.cpp k is 0 line 14
>>
>> C:\cint>cint gsm.cpp k is 1 line 16
>>
>> I encounter the issue with CINT v5.16.25 (checkout from cvs using
>> tag v5-16-25) compiled by MSVC7 (Toolkit2003), note that v5.16.24
>> is
> without
>> the issue.
>>
>>
>>
>> I just tried latest v5.16.27, also has the issue.
>>
>>
>> Thanks & Regards, Liu Bin
>>
>
>