What's the difference between C + + and C under Linux and under Windows?

Source: Internet
Author: User

I. Differences in function libraries

The C function library under Linux is not the same as the mechanism of function library system under Windows, GLIBC contains the main C library.
This library provides basic routines for allocating memory, searching directories, opening closed files, reading and writing files, string processing, pattern matching, mathematical calculations, and so on.

The mechanism is different not only refers to the problem of the interrupt number, the interrupt number is also through the input parameter and output to locate the function address and address in the register, those functions under Windows and Linux implementation should be different, take the file system, How can EXT3 and FAT32 be the same. There are also mm memory management, are not the same. Interrupts or hardware layer, the X86 should be similar, but the implementation of the operating system layer is very different.

The Windows C library format is. dll, which is an abbreviated form of the dynamic link library, which is a library that contains code and data that can be used by multiple programs at the same time, and DLLs are not executable files. The generated *.exe.

The Linux C Library format is. SO (.) for shared libraries: Dynamic library (shared library/shared object/dynamic link library). Build *elf (Linux elf elf = executable and linkable format), executable connection formats, is the UNIX System Lab (USL) as an application binary interface (application binary Interface, ABI) developed and published. The extension is elf).

Standard C library functions, as well as data types, can be compiled and run under any operating system, and the effect is exactly the same, but the internal implementation principle and storage method are not necessarily the same. The actual implementation of these library functions on different system operating systems is dependent on the API of the operating system itself. Linux is, of course, the Linux API, while Windows is the Windows API. Like the most common fopen function, he is implemented through the CreateFile function on Windows, while Linux is through the open function. The API is plainly a function, which is usually referred to as an operating system function. The Linux shell is the command line for Windows, which is simply an environment for parsing commands and executing programs. This environment is in fact a separate program. For any platform program to run, it relies on the operating system's API.

Two. Other differences

1) System platform is not the same
The underlying development involves the kernel of the system, and for Linux, you can know what the structure is, while Windows ...

2) compiler environment is different
Linux uses the GCC compiler, GDB debugging tools, and a variety of visual editors such as Emacs,kedit and so on, there is also the text of the VI/VIM,GDB function is very powerful, personally think better than win. Despite the mingw,devcpp integration of the win under the GCC, but it is always uncomfortable ~,GCC support for the standard is quite good.

3) different for the crowd
Win under the main or commercial development, and the vast majority of programming enthusiasts like to belong to their own open and free system programming, do not want to imprison under the Windows (MS) surrounded.

4) The direction of development is not the same.
OpenSource's ideas have blossomed in the Linux land (see GPL ...).
Find information convenient, source code open, you can experience the fun of development.
Win, Ms gradually put a number of developers bound in its own system inside, development environment more and more fools, this can be called humanization? Get to the end ... May go further and farther ~

5) Copyright issues
Win under a lot of things are related to copyright issues, Linux free software, although the freedom of software, but a lot of many are free for commercialization ... Of course some need open source code, a lot of do not need. The difference between C + + is similar


Three. Summary

Linux is simply like Windows as an operating system, except that there are different ways and habits to use them. The exact difference is really big, but it's not something that can be clearly said here.

For C programming, the big difference is that the features that are provided to your system are different. This leads to the problem of so-called transplant problems and platform features. The metaphor for image points is that you can think of Linux and Windows as people. They all know a part of English, but one is Chinese and the other is German. If they know exactly what you are using in English, they will be able to help you with your work. If you speak English they do not understand, it is only in their native language to say to them. The result is that you don't understand the Linux you speak in German, and Windows that you speak in Chinese doesn't understand. So, if it's simple programming, then they're not much different. If it's complicated ... You are ready to translate one's native language into the other's native language.

Because of copyright reasons, the source code of the library function is generally not visible, but in the header file you can see its external interface.
Library functions are written by others, and you use them in your program.
First of all, the standard only specifies the interface of these functions and the requirements of the specific operational efficiency, these functions are specifically how to write to see the implementation of the various compilers and the platform.

If you use Visual Studio, Microsoft provides a part of the C runtime (CRT) source code, there will be memcpy,strcpy such as the implementation of functions, my Visual Studio 2005 under the path is C:\Program files\ Microsoft Visual Studio 8\vc\crt\src, you can compare the reference.

Other differences See: "The difference of linux/windows under C/D + + zz"


Four. Questions and Answers

1) What is the difference between a math library function for a C language and a standard library function? The standard of the

C language has changed several times, and now the standard C language refers to the C99 standard that was enacted in 99. The library of functions defined here is the C standard function library. Specifically, you can check the C Language Reference manual (C:a Reference manual,fifth Edition).

But in fact, every C + + compiler has its own library of functions, generally compatible with the C standard function library, but there are some individual details of the discrepancy. So, generally you just have to look at the library of the compiler you're using (usually you can get it from the help). The

Mathematical function is one of the standard library functions. The

Standard library function takes precedence and is platform agnostic. Application interface API functions are platform-dependent. The

compiler function refers to a class library function such as MFC/VCL, which must be brought into the library after it is packaged into a program. The

Standard library function is determined by the standard of a language, and API functions are provided by the operating system. Standard library functions are most often done by invoking API functions to achieve their goals. But when I'm using it, I think it's best to call the standard library function implementation. This is a much better transplant. The
Standard library function is naturally preferred, and the standard library can be implemented independently of the platform.
If using the system programming, use the API, but the general IDE will have the API encapsulation, such as MFC, so it is more convenient to use MFC. Of course there are times when it is convenient to solve some problems directly with the API.

Compiler function? If you refer to MFC and the like, I said,

Otherwise if you use C + +, the general compiler has to implement the standard library. Just use the standard library directly.
There are also some other popular libraries available. C + + 's quasi-standard library boost, you can refer to www.boost.org.
Qt under Linux is a GUI library, similar to MFC under Windows, but is implemented in standard C + +.


Standard library functions: is a program specification that provides a set of standard functions that may have several specifications, such as C99, Standard C
Compiler function: is used to tell the compiler how to compile your program, such as #define,#typedef
API functions: functions provided by the operating system to support operations on this platform, such as MFC
The standard library is a cross-platform that is very easy to standardize and standard. Compiler functions are generally provided by the compiler's class library, and the API is typically provided by the operating system. The latter both have certain limitations


What's the difference between C + + and C under Linux and under Windows?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.