First knowledge of D language by Hello Word

Source: Internet
Author: User
Tags function prototype

Operating system: Linux

Compiler: GDC

In this article, you will use three methods to implement Hello Word, using the D standard Library, C standard library, and system call to demonstrate the basic appearance and system programming ability of the D language, only to make a presentation, as for the language knowledge in the following article will be described in detail


Using the D standard Library writeln function version

Import Std.stdio;void Main () {Writeln ("Hello", "world!");}


Using the C standard library puts function

extern (C) int puts (const char *); void main () {puts ("Hello world!\n". ptr);}


Call write directly using the system

extern (C) int write (int fildes, const void *buf, size_t nbyte), void Main () {write (1, "Hello world\n". PTR, 12);}


If you have other language basis, then D language syntax should look familiar, feel like C + + has no, but this is only the tip of the iceberg, and the difference between C + + is quite large, but from these three versions we can see the following characteristics of D language

Concept of a package

Support for variadic functions (actually support very good, write a function that supports variable parameters is also very simple)

Support directly call C function, only need to have the declaration of the C function prototype, of course, if you want to call the standard C and system call C function as long as the compiler function-LXX specify the name of the library to be linked, and C language consistent. As you can see from this point, D does not lose C + + in terms of system programming


If you are unfamiliar with the C language or unfamiliar with Linux, it may be difficult to understand the above example, first of all, to learn the D language, it is best to learn the C language, any one localization for the system programming language can not get rid of the C language, for D-C compatibility is binary compatibility, That is, D can directly use the C language compiled binary files, the advantage is that the syntax does not have to be compatible with C, you can redesign the language structure without C language problems, C + + is because from the source compatible with C, so C has a problem with the C + +, but also brought more problems, from this point of view C + + Design has a lot of problems, and D is designed to be a better system programming language.

Some people may ask, D language can do web development, of course, PHP can do a simple language can do, but there is no particularly comprehensive framework and related library procedures, if you want to consider the direct use of fastcgi, or using VIBE.D (an asynchronous IO network library that looks a bit like node. JS's design, so far it's done well. For details, please follow http://vibed.org)

This article is from the "Li Yunxing blog" blog, make sure to keep this source http://quetzal.blog.51cto.com/3313934/1631558

First knowledge of D language by Hello Word

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.