Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to migrate c to d0

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to transplant c to d0". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn "how to transplant c to d0".

Convert enumerations only need to copy / paste.

/ / In C

Enum

{

ME_FOO

ME_BAR

ME_BAZ

}

/ / In D

Enum

{

ME_FOO

ME_BAR

ME_BAZ

}

Note that there is no semicolon in d and there can be a comma. Name the enumeration with a prefix.

/ / In C

Typedef enum

{

ME_FOO

ME_BAR

ME_BAZ

} MyEnum

/ / In D

Enum MyEnum

{

ME_FOO

ME_BAR

ME_BAZ

}

/ / in the function

MyEnum me = MyEnum.ME_FOO;// here

Mainly for type safety, convenience and compatibility:

Alias MyEnum.ME_FOO ME_FOO

Alias MyEnum.ME_BAR ME_BAR

Alias MyEnum.ME_BAZ ME_BAZ

/ / add an alias

MyEnum me = ME_FOO

But the above is too redundant, if security is not important, you can do this:

Alias int MyEnum

Enum

{

ME_FOO

ME_BAR

ME_BAZ

}

This is the same as c's behavior.

# define,c is used to define constants. Enumerations in d can represent not only traditional enumerations, but also list constants, so there is no need to use invariant qualifiers. List constants are enumerations that contain only one member, so there is no need for parentheses.

/ / floating list constant

Enum float Foo = 1.003f

/ / declare with a dynamic reference that the mei can automatically derive the type.

Enum Foo = 1.003f; / / float

Enum Bar = 1.003; / / double

Enum Baz = "Baz!" / / string

/ / the following example:

/ / C terminal

# define FOO_SOME_NUMBER 100

# define FOO_A_RELATED_NUMBER 200

# define FOO_ANOTHER_RELATED_NUMBER 201

/ / D side

Enum FOO_SOME_NUMBER = 100

Enum FOO_A_RELATED_NUMBER = 200

Enum FOO_ANOTHER_NUMBER = 201

/ / grouped into a group

Enum

{

FOO_SOME_NUMBER = 100

FOO_A_RELATED_NUMBER = 200

FOO_ANOTHER_NUMBER = 201

}

If it is too much, group it into one group, and do it alone if you have two players. There can be more than one string.

/ / In C

# define LIBNAME "c library"

# define AUTHOR "XX"

# define COMPANY ""

/ / D, all can be added to the string

Enum: string

{

LIBNAME = "c library"

AUTHOR = "XX"

COMPANY = ""

}

Of course, Mei: (inheriting) other structures are also possible. Pay attention to the tail comma.

Structure, most c structure, can be slightly / even without modification. Change it directly to d

/ / In C

Struct foo_s

{

Int x, y

}

Typedef struct

{

Float x

Float y

} bar_t

/ / In D

Struct foo_s

{

Int x, y

}

/ / No semicolon.

Struct bar_t

{

Float x

Float y

}

It is mainly typedef. Sometimes there are two structural names.

Thank you for your reading. the above is the content of "how to transplant c to d0". After the study of this article, I believe you have a deeper understanding of how to transplant c to d0. The specific use of the situation also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report