Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compiler Bugs

Status
Not open for further replies.

xGE

Technical User
Nov 30, 2000
8
US
I am using Standard Borland C++ Builder 3.0 (build 3.70).

I have found what I consider to be compiler errors (2 probably related). Does anyone in the world care to know about these compiler bugs? Very tiny (~20 lines) test program available on request.
 
xGE,

[tab]Go ahead and put the code here. Be sure to prefix the code with
Code:
 and suffix with
(see "Process TGML" below) so the code is listed correctly. Be aware that there is a patch for BCB 3 at Borland's web site.



James P. Cottingham

All opinions are mine alone and do not necessarily reflect those of my employer.
 
Code:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <string.h>
#pragma hdrstop

//////////#include &quot;CompilerTest.h&quot;
// For convience the *.h file has been inserted directly below.


//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
    TButton *StartTest;
    void __fastcall StartTest_Click(TObject *Sender);
private:	// User declarations
public:		// User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------




//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;

void TestMe(int Index, String Str,  int* pOcc);


//---------------------------------------------------------------------
// This program demonstrates 2 problems that may very well be related.
//---------------------------------------------------------------------

//---------------------------------------------------------------------
// Begin problem #1
//---------------------------------------------------------------------
const  String gksExeDir = &quot;C:\\Program Files\\xxx\\Exe&quot;;
const  String gksIniDir = &quot;C:\\Program Files\\xxx\\Ini&quot;;
const  String gksFileCompare_LDFN   = &quot;FileCompare_LastDir.Ini&quot;;
const  String gksFileCompare_LFFN   = &quot;FileCompare_LastFiles.Ini&quot;;

//-----------------------------------------------------------------------------
// Going back to the old &quot;constructor&quot; method of initialization DOES work.
// (work == the two LHS constants end up with distinct values)
const String gksFileCompare_LastDir   ( gksIniDir + &quot;\\&quot; + gksFileCompare_LDFN);
const String gksFileCompare_LastFiles ( gksIniDir + &quot;\\&quot; + gksFileCompare_LFFN);
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
//  These lines do NOT work.  It compiles with no warning nor error, but as
// it turns out, both LHS values are identical.  Checking of the addresses of
// both LHS variables shows that both have the same address.  
const String Bad_gksFileCompare_LastDir  = gksIniDir + &quot;\\&quot; + gksFileCompare_LDFN;
const String Bad_gksFileCompare_LastFiles = gksIniDir + &quot;\\&quot; + gksFileCompare_LFFN;
//-----------------------------------------------------------------------------


TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    int i;
    int AddressLHS1, AddressLHS2;
    int AddressLHS1_Bad, AddressLHS2_Bad;
    AddressLHS1     = (int)&gksFileCompare_LastFiles;
    AddressLHS2     = (int)&gksFileCompare_LastDir;
    AddressLHS1_Bad = (int)&Bad_gksFileCompare_LastFiles;
    AddressLHS2_Bad = (int)&Bad_gksFileCompare_LastDir;

    //-----------------------------------------------------------------------------
    // Put a BREAK at the following line and observe that both gksFileCompare_LastDir
    // and gksFileCompare_LastFiles are IDENTICAL in value, and AddressLHS1_Bad
    // and AddressLHS2_Bad are IDENTICAL.  Whereas, AddressLHS1 and AddressLHS2 are
    // distinct.
    //-----------------------------------------------------------------------------
    i = 1;

    //---------------------------------------------------------------------
    // End problem #1
    //---------------------------------------------------------------------
}


//---------------------------------------------------------------------------

void __fastcall TForm1::StartTest_Click(TObject *Sender)
{
    int Index, Occ;
    int* pOcc = &Occ;
    String Str;
    
    TestMe(Index, Str , pOcc);

    int i = 1;    

}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------
// Begin problem #2
//---------------------------------------------------------------------
void TestMe(int Index, String Str,  int* pOcc)
{
    int i;
    
    String sJunk;
    String   OrigReplaceStr;
    String   ReplaceStr;

    ReplaceStr     = &quot;Valid Text&quot;;
    OrigReplaceStr = ReplaceStr;
    ReplaceStr[1] = 'X';

    //---------------------------------------------------------------------
    // Put a BREAK at the following line and observe that both OrigReplaceStr and
    // ReplaceStr have an &quot;X&quot; as the first character.  THAT'S BAD.    
    //---------------------------------------------------------------------
    i = 1;    

    // D A N G E R     ----  W A R N I N G   ---   SPASTIC COMPILER
    // If the seemingly stupid code below is not done, then the compiler apparently
    // sets the pointer for OrigReplaceStr to be equal to that of ReplaceStr.
    // With the result that when ReplaceStr[n] is executed, the value of
    // OrigReplaceStr is ALSO CHANGED.
    {   int Len = ReplaceStr.Length();
        sJunk = &quot;abc&quot;;
        OrigReplaceStr = ReplaceStr + sJunk;
        OrigReplaceStr = OrigReplaceStr.SubString(1, Len);
        ReplaceStr[1] = 'Q';
        
        // Put a BREAK at the following line and observe that
        // OrigReplaceStr still = &quot;Xalid Text&quot;, but
        // ReplaceStr now = &quot;Qalid Text&quot;.   , as it should.
        i = 1;    
    }
//---------------------------------------------------------------------
// End problem #2
//---------------------------------------------------------------------
}
 
xGE,

[tab]I have looked at you code but I do not have the time to thoroughly check it out. My own job is requiring me to work long hours until after the first of the year. BCB3 is an older compiler. They have released BCB 5 and I understand they are working on BCB6. You might want to join the Borland community at . It's free and will give you access to all their FAQs and tech notes.



James P. Cottingham

All opinions are mine alone and do not necessarily reflect those of my employer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top