Jesus 'n Jim
A mainly PC (some Mac) site w/Software, Computer Repair Info, How-To's on Using Computers
Technical Support 1-360-521-2060 (my business line cell)

Borland C++ 5.5.1 (free)

 

0. Get the compiler

trial and free compilers are available from here. Borland C++ 5.5.1 command-line compiler is available from here. this compiler is no longer available from embarcadero, in fact, they only offer trials, no free products.

BCC5.5.1 features:

for those of you who have it...

  • supports Native Multithreading
  • is 32-bit, does not generate 64-bit executables. If you want 64-bit executables, go for the free mingw-w64 or buy a borland compiler.
  • supports the microsoft 64-bit type __int64
  • has the borland version of microsoft's conio.h which is greatly enhanced with gotoxy(), attr() (compared to microsoft's bare set) and a number of other useful functions.
  • has a graphic TUI debugger!
  • does not support TR1 or Boost - compiler dated 2006, before these technologies came out.
  • has STL (although older and uses .h)
  • is missing strpos and one other necessary string function

1. Service Packs (patches)

If you downloaded the compiler, you will need the service packs.

BCC5.5.1 service packs/updates are available here. service packs for other compilers are available at support.borland.com or microfocus.com. for SP1 you will need to copy the zip file into the C:\Borland\BCC55\ directory/folder and unzip it. Windows XP has "Compressed (zipped) Folder" support, which means .ZIP file handling is built into the OS - simply right-click on the file folder bcc55sp1.zip that has a zipper running up it and pick "Extract All..."

2. bugs

  • Microsoft Visual C++ compatibilty: strdup() instead of _strdup() (but at least the name is compatible with __GNUC__). If you are trying to write cross-compiler code, you will need to find a way to disable __BORLANDC__'s strdup(). but that was with bcc5.5.1 (2006). somebody check if this is still true for the current compiler.
  • Microsoft Visual C++ compatibilty: _strpos() is missing and there is no equivelant. __GNUC__ doesn't have any equivelant either. but that was with bcc5.5.1 (2006). somebody check if this is still true for the current compiler.
  • Microsoft Visual C++ compatibilty: strlwr() is defined, but MSVC uses _strlwr(). __GNUC__ also has strlwr(). . but that was with bcc5.5.1 (2006). somebody check if this is still true for the current compiler.
  • I have not been able to get Microsoft resource files to compile with Borland's brc32.exe properly. I have been using brc32 -32 -V4.0 somename.rc after compiling the program, which should compile the resource into somename.exe. I get a .res file, but the EXE has no resources. I have never built a windows program and have no instructions. charles petzold's book is no help from what I've seen so far. anyone who knows how to build a windows program in proper sequence please email me. BTW, I can get the same program to work with the Microsoft VC++ 6.0 compiler. straight win32 code. but that was with bcc5.5.1 (2006). somebody check if this is still true for the current compiler.

3. Code you can include

Disclaimer: This code is provided without warranty and at your own risk. Nor am I saying it is fit for any purpose.

For this code to work, the comments must be put into a C++ file of some kind or a .h file. if you wish, you can C-ize the comments and delete the extraneous code.

#include <math.h>
#include <stdio.h>
#include <string.h>

#if defined(__BORLANDC__)
//but Borland C++ 5.5's strdup always returns NULL.  ugh.  not compatible with
// MSVC, which defines _strdup().  so we must recreate a new definition.
/*char * _strdup(char * str) {
    char * p = (char *)malloc(strlen(str)+1);
    if (p != NULL) {
        strcpy(p, str);
    } else {
        //printf("out of memory.");
    }
    return p;
}*/
char * _strdup(char * str) {
    return strdup(str);
}
#elif defined(__GNUC__)
char * _strdup(char * str) {
    return strdup(str);
}
#elif defined(_MSC_VER)
//do nothing, _strdup works on microsoft compiler
#else
char * _strdup(char * str) {
    char * p = (char *)malloc(strlen(str)+1);
    if (p != NULL) {
        strcpy(p, str);
    } else {
        yy_fatal_error("out of memory. lex bailing out.");
    }
    return p;
}
#endif


//this is sscanf for doubles. it functions in Borland C++ 5.5, whose sscanf %f doesn't work.
//this code is not fully tested, but it should work.
double readDoubleAscii(char * yytext) {
    double n=12.0; float nn=12.0; int mantissaL=0, exponent=0;
    double multiplier=0.1;
    char * p = yytext;
    bool negativeExponent=false, negativeMantissa=false;
#if defined(__BORLANDC__)
    //apparently there is a bug in sscanf in borland c++ 5.0 for doubles. it never touches the variable.

    //skip past leading spaces
    while (' '==*p || '\t'==*p || '\n'==*p || '\r'==*p) {
        p++;
    }
    // ("+"|"-")?{DIGITS}(\.{DIGITS}([eE]("+"|"-")?{DIGITS})?)?
    // ("+"|"-")?
    if ('-'==*p || '+'==*p) {
        switch(*p) {
        case '-':negativeMantissa=true;break;
        case '+':break;
        }
        p++;
    }
    n=0.0;
    while (isdigit(*p)) {
        mantissaL = 10 * mantissaL + (*p-'0');
        p++;
    }
    n = mantissaL;
    // (\.{DIGITS} ... )?
    if ('.'==*p) {
        //do nothing for now
        p++;

        // digits after the .
        while (isdigit(*p)) {
            n += multiplier * (*p-'0');
            multiplier /= 10.0;
            p++;
        }
    }
    // ([eE]("+"|"-")?{DIGITS})?
    if ('e'==*p || 'E'==*p) {
        p++;
        if ('-'==*p || '+'==*p) {
            switch(*p) {
            case '-':negativeExponent=true;break;
            case '+':break;
            }
            p++;
        }
        while (isdigit(*p)) {
            exponent = 10 * exponent + (*p-'0');
            p++;
        }
        //last step
        if (negativeExponent) {
            exponent=-exponent;
        }
    }
    //last step.
    if (negativeMantissa) {
        n=-n;
    }
    if (0 != exponent) {
        n = pow(n,exponent);
    }
//    printf("%s=%f\n", yytext, n); //DEBUG

#else
    sscanf(yytext, "%f", &n);
#endif
    return n;
}

#if defined(__BORLANDC__)
/*char * _strlwr(char * s) {
    char * p=s;
    while (*s != '\0') {
        if (*s>='A' && *s<='Z') {
            *s+='a'-'A';
        }
        s++;
    }
    return p;
}*/
char * _strlwr(char * s) {
    return strlwr(s);
}
#elif defined(__GNUC__)
char * _strlwr(char * s) {
    return strlwr(s);
}
#endif

#if defined(__BORLANDC__) || defined(__GNUC__)
int strpos(char s[], char c) {
    int i;
    for (i=0; s[i] != '\0'; i++) {
        if (s[i] == c) {
            return i;
        }
    }
    return -1;
}
#endif

4. Tips to get going

If you happen to have access to MSDN for Microsoft Visual C++ 6.0, you have the documentation you need to get going. But don't get excited and think you have access to ftell64 and fseek64, they're (currently) flaky on windows. those are from microsoft's latest compiler and not available on this particular version anyway.

to compile a generic program, I use this wrapper batch file bcc.cmd. it compiles for the pentium, but you can change it from the -5 to a -4 or -6 or just remove it. (everything is a -6 nowadays, but there are older machines out there) it spares me from fussing with switches all the time. I don't want to memorize them. just don't choose open when you download it or you'll just get help flashing by and no download. save.

Downloads

Download Now
compiler-wrapper.zip (4/24/2012)


Documentation

C:\prj\test\conio>bcc
if you need to reset bcc, do the following: bcc reset
bcc - batch file compiler wrapper for Borland C++ compiler.
usage:
    bcc [-[-]?^|/?^|-[-]h[elp]^|/h[elp]] [-[-]v[er[sion]]|/v[er[sion]]]
    bcc [32] [[-[-]]pack] [[-[-]]lowopt/-O/-O2] [[-[-]]windows] [[-[-]]console]
[[-[-]]debug/-g] [[-[-]]rc file.rc]  [[[-[-]]]reset] baseNameOfEXEorDLLorOCX EXE
orDLLorOCXextension sourcefile [sourcefile ...]

-? or /? or -h or -help or no arguments gives this help
-v or /v or /ver or /version or -version gives the version of bcc.cmd
defaults to 32-bit code and -O2 (lowopt) optimization
for 32-bit, a monolithic windows executeable will be created. for 64-bit, a dll
is required.  I don't know how to get around that: email me.
[[-[-]]pack] does the -fpack-struct and removes holes between structures.
[[-[-]]noopt] specifies no optimization.
[[-[-]]lowopt|-O|-O2] specifies optimization levels.
[[-[-]]debug|-g], generate debug info in the executeable for debugging with gdb.
  otherwise, it is stripped with -s -fstack-check to make smaller executeables.
[[-[-]]rc filename.rc] filename specifies a windows resource you wish to compile
 and automatically link in. in.
[[-[-]]windows] specifies a windows program.  can be used in conjunction with -c
onsole.
[[-[-]]console] specifies a console program  can be specified alone or with -win
dows.
[[-[-]]reset] resets the variables of this batch file (such as the path - they a
re kind of sticky unless you change from 32-bit to 64-bit, or necessary if you c
hange the batch file).
[-[-]ass[embl]yver[sion] 1.0.0.0] specifies version number for manifest - should
 match your program's version number.  default is 1.0.0.0 and this only works if
 you specify a manifest.
[[-[-]]v[er[sion]]] gives the version of this batch file.
errors and warnings are kept in the file errbcc.

example: bcc netapp exe netapp.cpp c:\borland\bcc55\lib\user32.lib c:\borland\bc
c55\lib\wsock32.lib c:\borland\bcc55\lib\ws2_32.lib
example: bcc netapp exe -rc menus.rc netapp.cpp c:\borland\bcc55\lib\libuser32.l
ib c:\borland\bcc55\lib\wsock32.lib c:\borland\bcc55\lib\ws2_32.lib
!edit at the top of the batch file to put in your PATH to BCC55 or other borland
 compiler bin\ directory!

C:\prj\test\conio>

I think I figured out how to compile an rc file and link it in. if I was wrong, please contact me and tell me how to compile a windows program WITH a .rc file using this compiler, and I'll try to remember to post it here so everybody else can benefit.

If there is a free version of a borland compiler that generates 64-bit code, please let me know what it is called and where I can get it.

include directory

mingw-w64's include directories are multiple instead of just one like normal compilers, but bcc5.5.1 uses one include directory, c:\borland\bcc55\include\

c++ STL headers have a .h file extension on them for the most common ones like iostream and iomanip and fstream and ostream, vector, etc. older Borland compilers used .h on all their headers (in borland c++ 5.5.1, this compiler), so you have have to switch those out in #ifdefs. That was 2006. I don't think any modern compiler uses .h in STL anymore.

libraries and library directory

mingw-w64's lib directories are multiple instead of just one like normal compilers, but borland c++ and microsoft compilers use a single lib (this borland compiler uses c:\borland\bcc55\lib\) directory.

microsoft and borland compilers simply name the libraries gdi32.lib according to the DLL names. mingw prepends the word lib and changes .lib to .a