root/trunk/docsrc/D1toD2.dd

Revision 1323, 2.7 kB (checked in by walter, 2 years ago)

add migration guide start

Line 
1 Ddoc
2
3 $(D_S $(TITLE),
4
5     $(P There are many changes to the D programming language that affect
6     migrating source code from D1 to D2.
7     This is an outline of changes to look for and a guide to how to modify
8     the code.
9     See $(LINK2 features2.html, D 2.0 Enhancements) for a complete list
10     of changes to the language.
11     )
12
13     $(P This document is incomplete.)
14
15 $(UL
16     $(LI Core Language
17     $(UL
18     $(ITEMR new_keywords, New Keywords)
19     $(ITEMR global_variables, Global Variables)
20     $(ITEMR static_arrays, Static Arrays are now Value Types)
21     $(ITEMR immutable_string, String Literals are Immutable)
22     )
23     )
24
25     $(LI Phobos Library
26     $(UL
27     )
28     )
29 )
30
31 $(ITEM new_keywords, New Keywords)
32
33     $(P D2 adds the following keywords:
34     $(D_KEYWORD pure)
35     $(D_KEYWORD nothrow)
36     $(D_KEYWORD shared)
37     $(D_KEYWORD immutable)
38     Any use of them in D1 code must be renamed.
39     Any variable names starting with two underscores
40     should be renamed.
41     )
42
43 $(ITEM global_variables, Global Variables)
44
45     $(P Global variables are now, by default, stored in thread local
46     storage. To put them back in global storage, use the $(D_KEYWORD __gshared)
47     storage class:)
48
49 ---
50 int foo = 7; // D1 code
51 $(B __gshared) int foo = 7; // D2 equivalent
52 ---
53
54     $(P Carefully consider whether or not those variables actually should
55     go into thread local storage, rather than being implicitly shared
56     among all threads.
57     )
58
59 $(ITEM static_arrays, Static Arrays are now Value Types)
60
61     $(P In D1, a static array function parameter is passed by
62     reference, meaning a pointer to the start of the static array
63     is passed as an argument.
64     This means that any changes to the array contents made by the
65     function will be visible to the function's caller.
66     In D2, a copy of the whole static
67     array is passed as an argument. Changes to the array contents by
68     the function are not visible to the function's caller, as it is
69     a separate copy.)
70
71     $(P To migrate, add the keyword $(D_KEYWORD ref) to the parameter
72     declaration:)
73
74 ---
75 void foo(int[3] array);      // D1 code
76 void foo($(B ref) int[3] array);  // D2 equivalent
77 ---
78
79 $(ITEM immutable_string, String Literals are Immutable)
80
81     $(P String literals in D1 have type $(D_CODE char[]), but in
82     D2 they have type $(D_CODE immutable(char)[]).
83     To migrate usually involves doing a global search replace:
84     )
85
86     $(TABLE1
87     $(TR $(TH from)$(TH to))
88     $(TR $(TD char[])$(TD string))
89     $(TR $(TD wchar[])$(TD wstring))
90     $(TR $(TD dchar[])$(TD dstring))
91     )
92
93     $(P This will take care of most of the issues.
94     For the rest, where mutable strings are desired, there will
95     be some work necessary.
96     )
97
98 )
99
100 Macros:
101     TITLE=Migrating D1 Code to D2
102     WIKI=D1toD2
103     ITEMR=$(LI $(LINK2 #$1, $+))
104     ITEM=<hr><h3><a name="$1">$+</a></h3>
Note: See TracBrowser for help on using the browser.