VC 6.0 compiler bug 
Author Message
 VC 6.0 compiler bug

Maybe i woke up too early today, or this a bone head error on my side but i
think this is a bug in VC 6.0.

The following code fails with an error:

error C2040: 'pTrackName' : 'int' differs in levels of indirection from
'char *'
error C2440: 'initializing' : cannot convert from 'char *' to 'int' This
conversion requires a reinterpret_cast, a C-style cast or function-style
cast

// Get the count of CD Tracks for our array to hold the track names.
            NumFiles = pCdInfo->TrackNameList->NumElements();
            CdTrackNames  = new char* [NumFiles];

// Fill the CD Track array with the Cd track names from the list in the CD
information
            char *pTrackName;
            for( int Idx = 0  , pTrackName = (char *)
pCdInfo->TrackNameList->GetHead();
                 Idx < NumFiles && pTrackName != (char *)  NULL;
                 Idx++ , pTrackName = (char *)
pCdInfo->TrackNameList->GetNext())
            {
                CdTrackNames[Idx] = strdup(pTrackName );
            }

While changing the code for the for() statement to be (moved the init &&
assignment for each iteration of pTrackName out of the for(...):

// The following code compiles and generates no error message...

            char *pTrackName = pTrackName = (char *)
pCdInfo->TrackNameList->GetHead();
            for( int Idx = 0  ;
                 Idx < NumFiles && pTrackName != (char *)  NULL;
                 Idx++ , )
            {
                CdTrackNames[Idx] = strdup(pTrackName );
                pTrackName = (char *) pCdInfo->TrackNameList->GetNext()
            }

I could not try this with VC 5.  When I installed VC 6 i tried to keep VC 5
as well.  NO LUCK!!!  I can compile programs with VC 5 but they will all
fail when i try and run them, just a word to the wise...

Thanks,

Dano :)

--

Dan Doris

Please remove "_no_spam_under_penalty_of_law_" from previous e-mail in order
to contact me.

Use of the return address on this message for commercial purposes  is
prohibited.  The transmission of unsolicited commercial material  is
prohibited under federal laws (47 USC 227).  Civil penalties and claims of
$500.00 per occurrence (47 USC 227[c]) may be assessed for violations.



Wed, 31 Jan 2001 03:00:00 GMT  
 VC 6.0 compiler bug

Quote:

>Maybe i woke up too early today, or this a bone head error on my side but i
>think this is a bug in VC 6.0.

You are way too quick to assign the problem elsewhere.
That tendency will not last long in a programmer.  It will
either fall with experience or the person exhibiting it will
cease to be or never become an effective programmer.

Quote:
>The following code fails with an error:

>error C2040: 'pTrackName' : 'int' differs in levels of indirection from
>'char *'
>error C2440: 'initializing' : cannot convert from 'char *' to 'int' This
>conversion requires a reinterpret_cast, a C-style cast or function-style
>cast

This diagnostic is correct for your code.

[snip]

Quote:
>            char *pTrackName;
>            for( int Idx = 0  , pTrackName = (char *) pCdInfo->TrackNameList->GetHead();

Mixing declarations using initialization syntax with
ordinary assignment involving a different type is
not going to work.  Effectively, you have declared
pTrackName to be an int here, and tried to supply
an initial value that is not an int.

Quote:
>                 Idx < NumFiles && pTrackName != (char *)  NULL;
>                 Idx++ , pTrackName = (char *) pCdInfo->TrackNameList->GetNext())

Putting this much stuff into a "for" initialization section
is not promoting clarity, IMHO.

Quote:
>            {
>                CdTrackNames[Idx] = strdup(pTrackName );
>            }

>While changing the code for the for() statement to be (moved the init &&
>assignment for each iteration of pTrackName out of the for(...):

>// The following code compiles and generates no error message...

>            char *pTrackName = pTrackName = (char *) pCdInfo->TrackNameList->GetHead();

The above is begging for confusion on the reader's part.
The newly declared name pTrackName hides the one
used in the initializer.

Quote:
>            for( int Idx = 0  ;
>                 Idx < NumFiles && pTrackName != (char *)  NULL;
>                 Idx++ , )

I doubt this compiled with that trailing ",".

--Larry Brasfield
Above opinions may be mine alone.



Wed, 31 Jan 2001 03:00:00 GMT  
 VC 6.0 compiler bug
No bug.  I'll bet the following change will work also.
Replace this:
    for( int Idx = 0,
        pTrackName = (char*)pCdInfo->TrackNameList->GetHead(); ...
With this:
    int Idx ;
    for( Idx = 0,
        pTrackName = (char*)pCdInfo->TrackNameList->GetHead(); ...

In your "for" statement, you've started a declaration instead of a simple
comma-separated assignment.  To the compiler, it appears that you're declaring
two ints:  Idx, to which you give an initial value of 0, and pTrackName, which
you try to initialize with a char *.

Quote:

> Maybe i woke up too early today, or this a bone head error on my side but i
> think this is a bug in VC 6.0.

> The following code fails with an error:

> error C2040: 'pTrackName' : 'int' differs in levels of indirection from
> 'char *'
> error C2440: 'initializing' : cannot convert from 'char *' to 'int' This
> conversion requires a reinterpret_cast, a C-style cast or function-style
> cast

> // Get the count of CD Tracks for our array to hold the track names.
>             NumFiles = pCdInfo->TrackNameList->NumElements();
>             CdTrackNames  = new char* [NumFiles];

> // Fill the CD Track array with the Cd track names from the list in the CD
> information
>             char *pTrackName;
>             for( int Idx = 0  , pTrackName = (char *)
> pCdInfo->TrackNameList->GetHead();
>                  Idx < NumFiles && pTrackName != (char *)  NULL;
>                  Idx++ , pTrackName = (char *)
> pCdInfo->TrackNameList->GetNext())
>             {
>                 CdTrackNames[Idx] = strdup(pTrackName );
>             }

> While changing the code for the for() statement to be (moved the init &&
> assignment for each iteration of pTrackName out of the for(...):

> // The following code compiles and generates no error message...

>             char *pTrackName = pTrackName = (char *)
> pCdInfo->TrackNameList->GetHead();
>             for( int Idx = 0  ;
>                  Idx < NumFiles && pTrackName != (char *)  NULL;
>                  Idx++ , )
>             {
>                 CdTrackNames[Idx] = strdup(pTrackName );
>                 pTrackName = (char *) pCdInfo->TrackNameList->GetNext()
>             }

> I could not try this with VC 5.  When I installed VC 6 i tried to keep VC 5
> as well.  NO LUCK!!!  I can compile programs with VC 5 but they will all
> fail when i try and run them, just a word to the wise...

> Thanks,

> Dano :)

> --

> Dan Doris

> Please remove "_no_spam_under_penalty_of_law_" from previous e-mail in order
> to contact me.

> Use of the return address on this message for commercial purposes  is
> prohibited.  The transmission of unsolicited commercial material  is
> prohibited under federal laws (47 USC 227).  Civil penalties and claims of
> $500.00 per occurrence (47 USC 227[c]) may be assessed for violations.

-- Aaron
---------------------
Aaron J Margosis

Fortress-NT - NT Workstation/Server Security Utility:
    http://www.sunbelt-software.com/fortress.htm
ScrnSaveSwitch/Plus - Screen Saver Control Utility:
    http://www.ssswitch.com


Thu, 01 Feb 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. a bug in VC 7.0 (but not in VC 6.0)

2. How to use VC 7.0 C++ compiler from VC 6.0 IDE

3. BUG in compiler (tested on 4.2 and 6.0)

4. Another bug in the Visual C++ 6.0 compiler

5. Possible compiler bug in Visual C++ 6.0 ?

6. A Problem (possibly a bug) in Visual C++ 6.0 Compiler

7. VC++ 6.0 compiler bug?

8. bug in VC 6.0

9. A very big bug found in VC 6.0

10. BUG in VC 6.0 SP2

11. VC 5.0 and 6.0 Debugger Bug

12. bug in VC 6.0

 

 
Powered by phpBB® Forum Software