The difference between C language and Fortran language

Source: Internet
Author: User
Tags arithmetic require advantage

This paper introduces the differences between C language and Fortran language in detail.

1. C + + language and FORTRAN development background

In the process of programming language development, FORTRAN language is regarded as the special language of scientific computation. Later introduced FORTRAN90 and Fortran 95 version is no exception, although they can fully realize the same function of C + + language, but its software development environment and software integration and so on are far inferior to C + + language. In recent years, with the development of computer hardware and software technology, data structure, database management technology, visualization and computer graphics, user interface system integration and artificial intelligence are gradually applied to the structure analysis software, The design of structural analysis software is not limited to a single scientific calculation needs to involve a lot of software development fields. C + + language can provide such software development needs of the function, but with Fortran 90 is difficult to achieve, on the other hand from the software programming environment, the current Fortran 90 compiler is very few, and C + + language compiler system is quite popular, can run on various models, Easy to implement Cross-platform software system integration.

2. The difference between C language and Fortran language

Because of the difference between the two backgrounds, they are different, after comparing a few sets of source code, mainly have the following experience:

c The biggest advantage is flexibility, not only by struct to define the new data structure, while the C pointer can let us free and efficient processing of large data. In the UNIX system, because the whole operating system is written by C, so we also have a convenient C function library, direct use of system resources and enjoy the system to bring services to achieve some low-level, fast action. and Fortran from the beginning of the scientific calculation, its difference with C mainly shows:

* The speed of the complex number operation

* Program parameters and strings

* Dynamic management of memory

* Multidimensional Array processing

* Function call and parameter passing

2.1. The speed of complex operation

In complex operations, C + + can define the plural class, and can redefine all the arithmetic, and complex formulas can be solved by an expression. But its redefinition complex number arithmetic is done using functions, using a function to invoke it is slow, unless you are using the inline function, but you will encounter the following problems: First of all, the formula is disassembled, after the reorganization of the results, so the surface of the program code is very concise, but in fact is compiler do a lot of work, still have to pay a considerable amount of computational time cost.

As for FORTRAN, the biggest advantage is the complex number (complex number) of the operation, the complex number is one of the basic data types of FORTRAN, which is the lack of C (c basically only the real and integral type). Although C can also be defined by struct to achieve the purpose of complex arithmetic, it is likely to sacrifice program performance, or write a program that is quite tedious to reduce readability. Therefore, in a large number of and require high speed complex computing occasions, Fortran is actually more suitable than C.

However, since the plural is already one of the basic data types of FORTRAN, then Fortran compiler can be designed to make the plural special optimization, for example, if you encounter a shorter complex expression, it can be directly derived from the "mental Arithmetic" Real_part and Imag_ Part of the expression, like this:

Real (a) = ... ; Imag (a) = .....

So it takes only two steps to get the results. Until you encounter too long and too complex a formula to do the dismantling of the action.

The use of C to do complex numbers may require a circle, and the circles around it may not be small. However, if you need a composite data structure in your program, such as a custom data structure that includes floating-point numbers, integers, and strings, Fortran will only give up the white flag. Of course, Fortran if you want to do or can do, but not very convenient, and may also need to circle. However, using FORTRAN 90 is no problem, because Fortran 90 also has a struct structure similar to C to define the data type of the composite.

2.2. Program parameters and strings

C program can have parameter string column, Fortran is not. For example, when a program executes, you must enter a, B, c

Three parameters, which can be written in C:

int main(int argc, char **argv)
{
int a, b, c;
a = atoi(argv[1]);
b = atoi(argv[2]);
c = atoi(argv[3]);
}

And when the program executes, the arguments are passed in: a.out 12 15 18

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.