-1

I compiled two pieces of code using the Turbo C++ 3.0 and Borland C++ 5.02 compilers and came across some odd things. My two pieces of code are like these:

First piece of code

void main()
{
}

Second piece of code

#include <iostream.h>
#include <conio.h>

void main()
{
}

And I got these results from them:

  • Borland C++ (first piece of code): 51 KB
  • Borland C++ (second piece of code): 51 KB
  • Turbo C++ (first piece of code): 5.89 KB
  • Turbo C++ (first piece of code): 16.3 KB

I checked two Borland executable files with a hexadecimal viewer and realized they were exactly the same.

I examined the first piece of code from these compilers in IDA Pro and came across these graphs:

Turbo C++

Turbo C++

Borland C++

Borland C++

Now I have these questions I'd like you to answer:

  1. Why are Borland C++ compiled files the same when one of them clearly doesn’t have some include and another have?

  2. Why are Borland C++ compiled files that big? (nearly 10 times bigger) and what is compiled that have that much size?

  3. When I submit the first piece of code to this site, I can see the assembly code of the simple void main function and I realized that Borland C++ code is very much the same, but Turbo C++ assembly code is very very complicated and isn't the same. Why?

  4. Why does this simple code, that compiled with Turbo C++, create these many functions that you can see in it's graph?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dev-masih
  • 4,188
  • 3
  • 33
  • 55
  • use `tdump.exe` to see what is in the executables – M.M Jun 26 '15 at 14:47
  • In short: Turbo C++ buggy. But did you use optimizations? – Hi-Angel Jun 26 '15 at 14:50
  • I'm not sure i didn't change any setting for compilation in any of those softwares – dev-masih Jun 26 '15 at 14:51
  • 4
    Why do you compare what a 24 yo compiler and an 18 yo compiler do with what is not even valid C++ code? – Baum mit Augen Jun 26 '15 at 14:52
  • @MasihAkbari I'm pretty sure that the reason for different sizes of two files in Turbo C++ is precompiled headers. But it isn't really a bug unless you see the same problem with optimizations *(though it is bad anyway)*. – Hi-Angel Jun 26 '15 at 14:53
  • I'm working with behavior of how compilers do compile from back then to these days – dev-masih Jun 26 '15 at 14:53
  • @MasihAkbari if you meant that you're doing a research of a difference in a work of compilers, then I'd advice you to use something with source code — e.g. gcc. So you can get more information of the compiler. – Hi-Angel Jun 26 '15 at 14:58
  • @Hi-Angel if you can provide me with some documentation that says what are those precompiled headers, that would be great. – dev-masih Jun 26 '15 at 14:59
  • @MasihAkbari [precompiled headers](https://en.wikipedia.org/wiki/Precompiled_header) – Hi-Angel Jun 26 '15 at 15:00
  • Voted to close: Too broad. There are sooo many differences between the two. – Thomas Matthews Jun 26 '15 at 17:00
  • Are your measurements from Debug mode or Release mode? In debug mode, the compilers may be lazy (or helpful) and include all functions in libraries whether you need them or not. In release mode, the compilers tend to only include libraries functions your program uses. – Thomas Matthews Jun 26 '15 at 17:03
  • Are you compile to a ".com" or ".exe" format executable. The ".com" takes up less space than a ".exe" format. – Thomas Matthews Jun 26 '15 at 17:03

1 Answers1

2

I will do my best at answering these, but you may need to post your questions to the Borland forums for detailed answers. In any case, upgrade your compilers.

1-Why Borland C++ compiled files are the same when one of them clearly dosen't have some include and another have?

Your program has no functionality and is incorrect. (The main function returns an int, always.)

You can include all the header files you want. You don't use them, so there is no additional code generated.

Your program doesn't require any header files. The have the same functionality.

2-Why Boland C++ compiled files are that big? (nearly 10 times bigger) and what is compiled that have that much size?

There are many possibilities. You'll have to either look at the assembly code generated, machine code generated or post to the Borland forums.

This also depends on whether you compiled in Debug mode or in Release mode. It also depends on whether you compiled for static libraries or dynamic libraries.

Fundamentally, the Borland Compiler may be generating code that meets the standards required by later versions of Windows than Turbo C++ was required to support. Research the difference between ".com" and ".exe" formats.

3-When i submit First Code to this Site i can see the assembly code of simple void main function and i realized that Borland C++ code is very much the same but Turbo C++ assembly code is very very complicated and isn't the same, why?

See my answer to #2.

4-Why this simple Code that compiled with Turbo C++ create this much functions that you can see in it's graph?

Most likely because you are compiling in Debug mode; or because Turbo C++ is a simpler compiler, it doesn't optimize the libraries and code as much as Borland does. In Debug mode, there are symbolic information placed into the executable file.

By the way, the size of the executable may not be the size of the executable code placed in memory. The executable format allows for stuff other than executable code to be placed in the file, such as program symbols an line numbers.

Don't worry about program sizes anymore. Get the program working correctly, robustly and safely before optimizing for size.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154