Difference between Turbo C++ and Borland C++ compiler [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I compiled two code using Turbo C++ 3.0 and Borland C++ 5.02 compilers and come across some odd things my cods are like these :
First Code
void main()
{
}
Second Code
#include<iostream.h>
#include<conio.h>
void main()
{
}
and i got these results from them :
- Borland C++ (First Code) : 51KB
- Borland C++ (Second Code) : 51KB
- Turbo C++ (First Code) : 5.89KB
- Turbo C++ (First Code) : 16.3KB
I checked two Borland execute files with a hex viewer and realize they are exactly the same.
I examined the First Code form these compilers in IDA pro and come across these graphs :
Turbo C++
Borland C++
Now i have these question i'd like you to answer
1-Why Borland C++ compiled files are the same when one of them clearly dosen't have some include and another have?
2-Why Boland C++ compiled files are that big? (nearly 10 times bigger) and what is compiled that have that much size?
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?
4-Why this simple Code that compiled with Turbo C++ create this much functions that you can see in it's graph?
Sorry about this long question but if you can clarify this to me that would be awesome i'm so confused right now.

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.

Related

Do I need to type -std=c++17 (or whichever standard I want to use) every time I need to compile a C++ program? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I have the Windows 10 OS, use VS Code to write my C++ code and use CMD to compile my programs. I don't really know which standard the compiler in my PC (MinGW, gcc version 6.3.0) uses, but I just want to endure that it uses the latest one like C++14 or 17. Unfortunately, I need to type in -std=c++17 every time I need to compile my program using that standard. How do I set the desired standard as default?
Unfortunately, I need to type in -std=c++17 every time I need to compile
This is why build scripts exist. There are many arguments that you want to pass to your compiler at some point:
Source files (you may have multiple translation units = .cpp files)
Include directories
Libraries to link
Optimization level
Warnings
C++ standard
Symbol defines
...and many more compiler flags...
In bigger projects you may also have multiple build targets (and thus compiler invocations) and you don't want to do all that by hand every time either.
As a simple solution, you could write a .bat script that invokes the compiler with the right arguments for you. However, there are tools that do a way better job at this, such as make (generally only found in the Linux world) or MSBuild (part of Visual Studio). Then there are also tools that generate these scripts for you, such as CMake and several IDEs with their own project configuration files.
I just want to endure that it uses the latest one like C++14 or 17. Unfortunately, I need to type in -std=c++17 every time
-std=c++17 is exactly how you ensure that you're using the C++ version you want (in this case C++17).

Can the IDE directly read the C library source code? How to find the source code needed [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want to learn the source code of floor() in c Function library, so I use the Vs quick lookup definition function to find in VS, and then
I find that _Check_return_ _ACRTIMP double __cdecl floor(_In_ double _X); statement。
I don't know what to do next.enter image description here
Because there seems to be only a macro definition, no function definition。
Is it that I should not use the IDE to view the source code, I am a newbie。
In general, for C, no.
C code can be shipped in pre-compiled form, when you get:
A header file (mylibrary.h) that provides declarations of contents of a particular module of code.
A library (mylibrary.lib, mylibrary.dll, mylibrary.so and so on, depending on the exact type of library and the platform), this contains the code and data that are needed for the module.
These two files are enough; the compiler reads the header when you #include it in your code, and the linker "glues in" the necessary code and data from the library.
Note that there is no source code available.
The floor() function is part of the C runtime library and shipped with the compiler implementation; I'm not sure whether Microsoft provides the source for theirs. Of course there are open source implementations, here is the code from the "musl" implementation of the C standard library, for instance.
Most library functions are visible to your project just as prototypes, as they have been already compiled into a static (or dynamic) library. As far as functionality is concerned, the compiler could ship without those sources, as they are not necessary to compile your program. It's pretty much the same e.g. for OS APIs: you invoke them all the time, but you don't have the Windows sources.
On the other hand, Visual C++ traditionally shipped with the sources of (most of) its C runtime to aid debugging; they are usually found somewhere under your VC++ installation directory.
edit better indications in this answer; thanks #Martin R for digging it out

Best practice when building large libraries for project [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am currently working on a Raspberry Pi project that uses the OpenCV library, among others. The OpenCV library is quite large, and the build process for it is decently extensive. I found a script which downloads and installs the latest version of OpenCV, and following some suggestions from this question, I was able to build the library, and begin using the functions within OpenCV.
Considering the actual build process for OpenCV took considerably longer than building our project would, is it acceptable to just build the library once, as opposed to building the library each time we build our project?
While I realize this is probably personal preference, I am wondering how others handle situations similar to this.
As you probably already know, code that does not change does not need to be recompiled. This is true for executables and libraries alike.
A library is supposed to provide you addictional functionality in a neat, pre-packaged form. The difference between additional code you add to your project and a library is that the code included in a library is supposed to be in a stable state, so that once built the user will be able to use its features without any maintenance hassle; the APIs will be available and they will always work. You will be able to discard any implementation files, and just work with the header files - which provide you with the API within your code - and the library files, which contain the compiled implementation.
You are pretty much pre-compiling part of your program; a part that will also be able to be used in other projects, again without recompiling.
Note that C++ itself is an example of this: an implementation of the C++ standard library (for example libc++) is already included with your compiler, so that you are able to use the standard C++ headers without the need to recompile C++ whole every time you try a "Hello World!" program.
You can even extract libraries out of parts of your project that you feel are already completed and stable: this can allow you to reduce the time required to compile your project even though it becomes bigger. These reasons are part of why modularity is so strongly encouraged when programming.
TL; DR: Recompiling a library only once is not only acceptable, is most probably what you want to do.
It is normal to compile once and then only link the library. For that reason the compilers can detect whether there are changes in source files.

How C++ libraries work? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
As i know Windows operating system used the assembly language to interact with the hardwares.
When they did this,they could use c,c++ or any other language to the rest work.
As i know C++ header files actually call the windows api for the implementaion.
So where are header files located? Are them installed by compilers ? or they come with the operating systems?
What keyword or code do the header files use to interact with the sutable api(for example std::cout on windows,calls a function in a dll file and in linux an other)?
For example is iostream.h different on linux from windows?
And how that how they find suitable libraries?
And my last question is that,how libraries interact with assembly code?(so assembly code interacts with hardware)
TIA.
The following passage isn't meant to be any sort of complete description of how libraries, compilation processes or system calls invoking works but rather a bird-eye view of what OP asked, thus lacks several details and important passages which will have to be studied in-depth by the OP himself
By "C++ library" I assume you're referring to the C++ standard library (although the considerations here are valid for any other library as well).
The C++ standard library isn't mandatorily present on any operating system by default, it usually comes shipped with a compiler installation or with a secondary package. That doesn't mean you can't execute C++ compiled routines, you just need headers and the library in order to compile your programs along with a compiler which supports it.
The C++ standard library is usually compiled platform-specific and you can't just copy the headers and lib files from one operating system to another one (you'll end up in tears).
Everytime you import the declarations from a header file with something like
#include <iostream>
you're rendering your program aware of the moltitude of data structures, functions and classes provided by the standard library. You can use them as you want as long as you provide the .lib file (in a Windows environment) where the code of the routines is usually defined (in Visual Studio this is usually referred as the Runtime Library with /MT /MD options) for linking.
Once you've linked your executable against those .lib files, you have a compiled executable which, opened in a disassembler, might have something like (for a simple hello world, snippet from here - not a windows environment)
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
thus eventually every C++ function or routine provided by the standard library either implements an algorithm and/or eventually call some operating-system specific routines through System Calls. There are several design and implementation differences between the various operating systems (and even the boundaries of the system call points) in addition to a thousand of layers for security checking (not to mention ring3/ring0 switches) so I won't spend more words here about that.
You may try to install the Windows SDK and check the %PROGRAMFILES%\Microsoft SDKs\Windows directory.

Telling if C++ code is portable [duplicate]

This question already has answers here:
How to write portable code in c++?
(12 answers)
Closed 9 years ago.
I'm trying to write code that can be compiled with any modern version of g++ and am having difficulties. I wrote the code using Visual Studios and it worked fine but I tried compiling it on another computer and it had problems.
One problem was it didn't recognize the macro EXIT_SUCCESS. I see here it's defined in cstdlib but how come in VS I didn't need to import that library?
Also in a .h file I had const private int PI = 3.1416 and on the other computer it didn't like that.
So how do you know what's going to be portable? I thought C (and therefore inherently C++) was invented to be compiled anywhere. I asked this question but think it go misinterpreted, are there certain settings that must be done to the IDE to ensure portability?
EDIT: I might understand it better knowing why did the code compile in Visual Studio without include <cstdlib> and how do you turn off such feature?
In practice the only way to tell whether the code is portable is to compile it under all target compiler/platform. You can try to adhere to C++ standard but reality is harsh and there is no 100% complient compilers. Even simple program can give you surprises on other compilers.