×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Compiler Bugs

Compiler Bugs

Compiler Bugs

(OP)
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.

RE: Compiler Bugs

xGE,

    Go ahead and put the code here. Be sure to prefix the code with 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
 
www.ivcusa.com
All opinions are mine alone and do not necessarily reflect those of my employer.

RE: Compiler Bugs

(OP)
//---------------------------------------------------------------------------
#include <vcl.h>
#include <string.h>
#pragma hdrstop

//////////#include "CompilerTest.h"
// 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 "*.dfm"

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 = "C:\\Program Files\\xxx\\Exe";
const  String gksIniDir = "C:\\Program Files\\xxx\\Ini";
const  String gksFileCompare_LDFN   = "FileCompare_LastDir.Ini";
const  String gksFileCompare_LFFN   = "FileCompare_LastFiles.Ini";

//-----------------------------------------------------------------------------
// Going back to the old "constructor" method of initialization DOES work.
// (work == the two LHS constants end up with distinct values)
const String gksFileCompare_LastDir   ( gksIniDir + "\\" + gksFileCompare_LDFN);
const String gksFileCompare_LastFiles ( gksIniDir + "\\" + 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 + "\\" + gksFileCompare_LDFN;
const String Bad_gksFileCompare_LastFiles = gksIniDir + "\\" + 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     = "Valid Text";
    OrigReplaceStr = ReplaceStr;
    ReplaceStr[1] = 'X';

    //---------------------------------------------------------------------
    // Put a BREAK at the following line and observe that both OrigReplaceStr and
    // ReplaceStr have an "X" 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 = "abc";
        OrigReplaceStr = ReplaceStr + sJunk;
        OrigReplaceStr = OrigReplaceStr.SubString(1, Len);
        ReplaceStr[1] = 'Q';
        
        // Put a BREAK at the following line and observe that
        // OrigReplaceStr still = "Xalid Text", but
        // ReplaceStr now = "Qalid Text".   , as it should.
        i = 1;    
    }
//---------------------------------------------------------------------
// End problem #2
//---------------------------------------------------------------------
}

RE: Compiler Bugs

xGE,

    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 www.borland.com . It's free and will give you access to all their FAQs and tech notes.



James P. Cottingham
 
www.ivcusa.com
All opinions are mine alone and do not necessarily reflect those of my employer.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close