Revisiting Borland Turbo C/C++, a great IDE back in the 90s

5.00 avg. rating (94% score) - 1 vote

I have to admit, I was never a heavy user of Turbo C back in the day. My journey as a programmer started with Turbo Pascal, followed by QBASIC, and then Microsoft Visual Basic 3.0. Although I did have Turbo C 3.01 installed alongside with Turbo Pascal on my Tandy 1000 at the time, it was not until many years later that I began to play with Turbo C extensively, as part of an embedded system project at work.

Recently, with some free time, I downloaded Turbo C and Turbo C++ from winworldpc and played with them on NTVMx64. A “Hello World” program runs well on Turbo C 1.0, just as it should on a modern compiler:

tc10

Obviously, one could point out many limitations with such an early IDE. There is no syntax highlighting and no way to set a breakpoint. Online help is available but limited to IDE usage only and does not cover C language syntax.

The “Edit” menu seems annoying as it doesn’t seem to do anything (no submenus etc.) except to set the cursor to the edit window. This useless menu remained in Turbo C 2.0 and Turbo Pascal 5.5 and was only finally replaced with a full menu supporting Cut/Copy/Paste starting from Turbo C 3.0 and Turbo Pascal 6. Despite the useless “Edit” menu, the editor supports features such as block select, find, and replace using Wordstar shortcut keys, for example Ctrl-Q-F to find and CTRL-Q-A to replace. Most of these shortcut keys are described in online help:

tc10help

And yes, online help refers to help text which is bundled with the software package (e.g. floppy disks), and not from the Internet as many would assume. At the time, due to limited storage capacity, most software came with hard-copy manuals and online help was considered quite an achievement. Visual Studio 2008 also had “online” help (installed via the MSDN Library CD) and contains extensive documentation of the C language (among others) – you can just place the cursor on a C function and press F1. In newer versions of Visual Studio, language help is simply provided by pointing the browser at the relevant MSDN page.

As the IDE files are dated 6 July 1987 and ANSI-C was not finalized until 1989 (referred to as C-89), many features taken for granted in modern C compilers are not available. For example, single line comments such as

// this is a comment

are not accepted and will produce an “expression syntax” error. Obviously, more modern features such as binary notation (0b10101010) are also not accepted either – you must use hex notation, e.g. 0xAA instead. Even Visual Studio 2008 does not support this as binary notation is part of C++ 14 and is only supported from Visual Studio 2015 onwards. I wonder how many things the modern software developer is taking for granted nowadays.

In Turbo C 1.0, declaring function parameter types is optional and int will be assumed. The following would compile and work properly:

void test(a, b)
{
   a = 4;
   b = 5;
   printf("%d %d\n", a, b);
}

void main()
{
  test(4,5);
}

The following would still compile but would cause undefined behavior (most likely a hang or crash) due to stack imbalance as the Turbo C compiler fails to detect that the required parameters are not provided:

void test(a, b)
{
   a = 4;
   b = 5;
   printf("%d %d\n", a, b);
}

void main()
{
  test();
}

The following will cause a compile error (too few parameters) – Turbo C correctly detects missing parameters if the parameter types are declared:

tc10er

In Turbo C 2.0, Borland added support for breakpoints and online help for C language. Place the cursor on a word and press Ctrl-F1 to get relevant help. Online help still does not contain code examples (which were finally added in Turbo C 3.0). The IDE color theme is now yellow-on-blue:

tc20help

Obviously you can’t set a breakpoint in a comment or on lines which otherwise produce no codes (e.g. declaration without initializers). If you do this in a modern IDE like Visual Studio, the breakpoint will be automatically moved to the next accepted line. If you do this with Turbo C, a message (Invalid Breakpoint, ignore, Erase, Clear all bad, Skip all bad) will be shown the next time the code is run:

tc1bp

A PhD in computer science working at my office once tried to do exactly this for Visual Studio and complained that the IDE is buggy. Don’t get me into this :)

Turbo C 2.0 also supports graphics using Borland Graphics Interface (BGI). You can get a demo of the supported features by running BGIDEMO.C:

bgidemoc

If the code doesn’t compile, check Options > Directories and make sure that the path is set correctly (e.g. C:\TC\INCLUDE for the include directories). Also check Options > Linker and turn on linking for Graphics Library. The Turbo C installer set these values upon installation, but if you later moved the TC directory, these paths must be manually changed:

tcdir

As with these early IDEs, code can be compiled and run without ever saving the file to disk! One must press F2 every time, else data will be lost if the computer needs to be restarted. I believe the feature is designed to avoid excessive floppy disk writes. This behavior is also true for Turbo Pascal. However, Free Pascal, a Turbo Pascal clone, prompts the user to save the file before the first compilation and auto-saves during subsequent compilation.

In Turbo C/C++ 3.0, syntax highlighting and code examples are added:

tc30

An option to show 43 lines for EGA and 50 lines for VGA is also added to Options > Preferences:

tc3050

I seldom use this feature on a physical PC, because character height is shrunk (to cater for more lines) making the text hard to read:

PXL_20230325_050429707

However, on an emulator, this can be useful as the window height is now expanded and more lines can be displayed, but not at the expenses of character height. Here is a screenshot in 50 lines mode of the help window describing the “auto” keyword arguably the most useless keyword in the C language:

tcauto

According to the above help text, having a local lifetime is the default for local variables and therefore the auto keyword is rarely used. If so, when do you need to use this keyword? I leave this as an exercise for the reader.

Turbo C 3.0 also has support for mouse, windowed editing, debug watches and projects, features we are all too familiar with on a modern IDE. To go to a function declaration, use Search > Locate function, which only works after your code has been successfully compiled. Except for auto-complete which is useful for complicated projects, the IDE is considered quite matured.

Free Pascal IDE tried to implement auto-completion, which is rather limited and only works for certain keywords (procedure, begin, end, repeat, etc.) and does not work for function parameters. The list of available keywords can be configured in Options > Environment > CodeComplete:

fpauto

Turbo C 2.0 was the last version to run on a 8088. Later versions required protected mode (e.g. at least a 80286) but the compiled executables can run on a 8088 (with the correct linker settings). The libraries CONIO.H and DOS.H which contain several useful function such as clrscr(), gotoxy(), sound() and delay() work well even on modern machine and do not suffer from Runtime Error 200 like the CRT unit of Turbo Pascal. I previously used Turbo C to develop a MIDI player for the PC XT, see this article for details.

Various games such as Commander Keen – Keen Dreams were also developed using Turbo C. I once studied the code for this game and realized that it has several macros to enable support for Disney Sound Source. For example, inside id_sd.c, around line 1494, you can see that original detection routine which also covers Sound Blaster and Disney Sound Source has been commented out, leaving only support for Adlib and PC speaker:

#if 0	// DEBUG - hack for Keen Dreams because of no space...
// Use the best sound hardware available
if (SoundBlasterPresent)
	sd = sdm_SoundBlaster;
else if (SoundSourcePresent)
	sd = sdm_SoundSource;
else if (AdLibPresent)
	sd = sdm_AdLib;
else
	sd = sdm_PC;
#else
if (AdLibPresent)
	sd = sdm_AdLib;
else
	sd = sdm_PC;
#endif

However, once enabled, only random sounds could be heard as the actual audio samples meant to be played on a Disney Sound Source device was never ready, explaining the reasons why the codes were commented out. No changes in audio were noted if Sound Blaster detection is enabled. The Sound Blaster is backwards compatible with Adlib and the game simply plays Adlib sound as there is no specific support for Sound Blaster, apart from the auto-detection. You can try it yourself by downloading the codes from the above Github repository and use Project > Open Project to open KDREAMS.PRJ project file.

If you use Turbo C to interface with the parallel port, like what I did, take note that the correct function to use is inportb and outportb from DOS.H. There are no inb/outb methods, no PORT/PORTW arrays, and no Mem/MemW/MemL to provide direct access to real mode memory (e.g. MEM[segment:offset]) unlike Turbo Pascal. To do the same, you will need to cast the address literal as a pointer and access the port using this pointer:

char* pointer = (char*)0x1173000;   // calculate using segment*16 + offset
char value = *pointer;
char first_byte = pointer[0];
char second_byte = pointer[1];

All in all, Turbo C is still a very useful IDE even today. I believe it is still being used by some Indian schools to teach students the basics of C language. It does not have features like autocomplete which is not really necessary and could undermine early learning efforts. No, I am totally against old-school professors who ask students to write hundreds of lines of codes on paper for a final exam, but remembering the basic syntax of printf() or strcpy() is certainly needed if one is ever going to be a good C developer. In any case, if you can’t write a program which (let’s say) displays the first 100 prime numbers with Turbo C, Visual Studio 2022 is not going to help you either. In my case, Turbo C is presently being run on an old machine to develop a modern-day emulator for an old piece of hardware, and the IDE has so far not disappointed me.

See also:

Developing a PC-speaker MIDI player for the IBM PC XT
Exploring Tandy Deskmate on DOSBox v0.7.4

5.00 avg. rating (94% score) - 1 vote
ToughDev

ToughDev

A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>