C source code porting, C source code porting

Source: Internet
Author: User

C source code porting, C source code porting

We know that many programmers abroad work in linux/unix environments, so there are many excellent c/c ++ language code that cannot be compiled directly on the windows platform.

 

In many cases, we can only use tools such as msys and cmake to compile a simulated environment.

 

In fact, sometimes it is unnecessary.

For example, once a pure c code is compiled and various environments such as MSYS, Mingw, SWIG, and Python are built, the results still cannot be compiled smoothly.

 

There are some. spec files.

 

Then try to use-I. To add any other compiler, get an empty project, add the c code to the project, compile,

 

OK.

 

The world is quiet. for tools such as Bison, this method may not work very well and is not platform-independent in general. This method is very OK.

 

Believe it or not, please try.


C language is troublesome

Programming
This is a problem in every game programming FAQ. This question is asked several times a week on the game development forum. This is a good question, but no one can give a simple answer. In some applications, some computer languages are better than others. The following describes the main programming languages used to compile games and their advantages and disadvantages. I hope this article will help you make a decision.

1. C Language

If FORTRAN and COBOL are the first generation of advanced compilation languages, C languages are their grandchildren. C language was created by Dennis Ritchie in 1970s. It is more powerful and maintains more continuous inheritance with ALGOL, while ALGOL is the structural successor of COBOL and FORTRAN. The C language is designed to be a more sophisticated and simpler version than its predecessors. It is suitable for compiling system-level programs, such as operating systems. Previously, the operating system was compiled in assembly language and cannot be transplanted. C language is the first programming language that makes porting system-level code possible.

The C language supports structured programming, that is, the C program is compiled into a set of separated function calls (CALLS). These calls run from top to bottom, unlike the code of a separate Integrated Block, the GOTO statement is used to control the process. Therefore, the C program is much simpler than the integrated FORTRAN and COBOL "Hollow powder code" code. In fact, C still has a GOTO statement, but its functions are limited. It is recommended only when the structured solution is very complex.

Because of its system programming roots, it is quite easy to combine C and assembly languages. Function calling interfaces are very simple, and assembly language commands can also be embedded in C code. Therefore, you do not need to connect to an independent assembly module.

Advantage: it is beneficial to write small and fast programs. It is easy to combine with assembly languages. With high standardization, the versions on other platforms are very similar.

Disadvantage: it is not easy to support object-oriented technology. Syntax is sometimes hard to understand and misuse.

Portability: C language and ANSI function calls are both portable, but limited to process control, memory management, and simple file processing. Other things are related to the platform. For example, to develop a portable program for Windows and Mac, the user interface needs to use function calls related to the system. This generally means that you have to write the user interface code twice, but some libraries can reduce the workload.

Games written in C language: very many.

Document: The typical C Language book is The C Programming Language. It has been modified several times and has been expanded to three times as large as The first one, but it is still an excellent book introducing C. An excellent tutorial is The Waite Group's C Primer Plus.

2. C ++

C ++ is the successor of C language with object-oriented features. Object-Oriented Programming, or OOP, is the next step in structured programming. An OO program is composed of objects whose objects are discrete sets of data and functions. There are a lot of available objects in stock, which makes programming as simple as simply putting together some program "Building Materials" (at least theoretically ). For example, there are many GUI and database implementations as a collection of objects.

C ++ is always the subject of debate, especially in game development forums. There are several C ++ functions, such as virtual functions, which add an additional level for decision making of function calls, critics soon pointed out that C ++ programs will become much slower than C programs with the same functionality. C ++ advocates believe that using C to write code equivalent to a virtual function will also increase expenses. This will be a debate that is still in progress and cannot be quickly concluded.

In my opinion, the extra cost of C ++ is only a small cost for using better languages. The same debate occurred in 1960s when advanced programming languages such as COBOL and FORTRAN began to replace assembly as language choices. Critics correctly point out that a program written in advanced languages is inherently slower than a handwritten assembly language, and must be so. High-level language support believes that such a small performance loss is worthwhile, because the COBOL and FORTRAN programs are easier to write and maintain.

Advantage: it is much better to organize large programs than the C language. It supports the object-oriented mechanism. General data structures, such as linked lists and... the remaining full text>

How to transplant C language programming

It means porting a sub-function program to use this function. I use C language to control the single-chip microcomputer. For example, I call a delay program to other programs, that is, copy and paste them.
For example, latency program:
Void delay (unsigned long v)
{
While (v! = 0) v --;
}

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.