diff -uNr dmd-0.129/dmd/html/d/abi.html dmd-0.130/dmd/html/d/abi.html --- dmd-0.129/dmd/html/d/abi.html 2005-05-19 15:08:50.000000000 +0200 +++ dmd-0.130/dmd/html/d/abi.html 2005-08-26 11:54:10.000000000 +0200 @@ -12,9 +12,15 @@ - - + + + + + + + + +
- +
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
D Application Binary Interface@@ -154,9 +215,10 @@ Passing abc to functions results in these implicit conversions:- void func(int array[3]); // actually@@ -197,15 +259,15 @@ TBD + |
+
Home
| Search
| D
+| Comments
|
+
+ + + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
Acknowledgements@@ -73,15 +143,15 @@ Matthew Wilson, Peter Zatloukal + |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Arrays@@ -57,11 +118,9 @@Pointers-
+ These are simple pointers to data, analogous to C pointers. Pointers are provided for interfacing with C and for @@ -75,11 +134,9 @@ Static Arrays-
+ These are analogous to C arrays. Static arrays are distinguished by having a length fixed at compile time. @@ -90,11 +147,9 @@ Dynamic Arrays-
+ Dynamic arrays consist of a length and a pointer to the array data. Multiple dynamic arrays can share all or parts of the array data. @@ -110,15 +165,13 @@ Prefix declarations appear before the identifier being declared and read right to left, so: -
+ Postfix Array Declarations@@ -127,9 +180,7 @@ declared and read left to right. Each group lists equivalent declarations: -
+ Rationale: The postfix form matches the way arrays are declared in C and C++, and supporting this form provides an @@ -170,9 +221,7 @@ The handle to an array is specified by naming the array, as in p, s or a: -
+
+ The [] is shorthand for a slice of the entire array. For example, the assignments to b: -
+ are all semantically equivalent. @@ -234,26 +279,22 @@ is not only handy for referring to parts of other arrays, but for converting pointers into bounds-checked arrays: -
+ Slicing for bit arrays is only allowed if the slice's lower bound falls on a byte boundary: -
+ Misaligned bit array slices will cause an ArrayBoundsError exception to be thrown at runtime. @@ -266,9 +307,7 @@ Array copying happens when the lvalue is a slice, and the rvalue is an array of or pointer to the same type. -
+ Overlapping copies are an error: -
+ s[1..3] = s[0..2]; error, overlapping copy Disallowing overlapping makes it possible for more aggressive parallel code optimizations than possible with the serial @@ -299,24 +336,20 @@ type of the lvalue, then the lvalue's array contents are set to the rvalue. -
+ Array ConcatenationThe binary operator ~ is the cat operator. It is used to concatenate arrays: -
+ Many languages overload the + operator to mean concatenation. This confusingly leads to, does: -
+ produce the number 13 or the string "103" as the result? It isn't obvious, and the language designers wind up carefully writing rules @@ -344,21 +375,17 @@ Similarly, the ~= operator means append, as in: -
+ Concatenation always creates a copy of its operands, even if one of the operands is a 0 length array, so: -
+ @@ -369,44 +396,34 @@ In general, (a[n..m] op e) is defined as: -
+ So, for the expression: -
+ the result is equivalent to: -
+ When more than one [] operator appears in an expression, the range represented by all must match. -
+ Examples:-
+ Rectangular Arrays@@ -436,11 +453,9 @@ access them via pointers to pointers resulting from "array of pointers to array" semantics. For example, the D syntax: -
+ declares matrix as an array of pointers to arrays. (Dynamic arrays are implemented as pointers to the array data.) Since the arrays can have varying sizes (being dynamically @@ -448,20 +463,16 @@ array rows can sometimes point to each other! Fortunately, D static arrays, while using the same syntax, are implemented as a fixed rectangular layout: -
+ declares a rectangular matrix with 3 rows and 3 columns, all contiguously in memory. In other languages, this would be called a multidimensional array and be declared as: -
+ Array Length@@ -469,9 +480,7 @@ the variable length is implicitly declared and set to the length of the array. -
+ Array Properties@@ -559,9 +568,7 @@Examples: -
+
+ This causes the array to be reallocated in place, and the existing contents copied over to the new array. If the new array length is @@ -599,9 +604,7 @@ This means that if there is an array slice immediately following the array being resized, the resized array could overlap the slice; i.e.: -
+ To guarantee copying behavior, use the .dup property to ensure a unique array that can be resized. @@ -632,9 +635,7 @@ Resizing a dynamic array is a relatively expensive operation. So, while the following method of filling an array: -
+ will work, it will be inefficient. A more practical approach would be to minimize the number of resizes: -
+ Picking a good initial guess is an art, but you usually can pick a value covering 99% of the cases. @@ -679,9 +678,7 @@ A program may not rely on array bounds checking happening, for example, the following program is incorrect: -
+ The loop is correctly written: -
+ Implementation Note: Compilers should attempt to detect array bounds errors at compile time, for example: -
+ Insertion of array bounds checking code at runtime should be turned on and off @@ -743,21 +736,17 @@ Static Initialization of Static Arrays-
+ This is most handy when the array indices are given by enums: -
+ If any members of an array are initialized, they all must be. This is to catch @@ -773,22 +762,18 @@ Bit vectors can be constructed: -
+ The amount of storage used up is implementation dependent. Implementation Note: on Intel CPUs it would be rounded up to the next 32 bit size. -
+ So, the size per element is not (x.size / x.length). @@ -806,12 +791,10 @@ just a dynamic array of characters. String literals become just an easy way to write character arrays. -
+ char[] strings are in UTF-8 format. wchar[] strings are in UTF-16 format. @@ -820,14 +803,12 @@ Strings can be copied, compared, concatenated, and appended: -
+ with the obvious semantics. Any generated temporaries get cleaned up by the garbage collector (or by using alloca()). Not only that, @@ -837,22 +818,18 @@ A pointer to a char can be generated: -
+ Since strings, however, are not 0 terminated in D, when transferring a pointer to a string to C, add a terminating 0: -
+ The type of a string is determined by the semantic phase of compilation. The type is @@ -862,11 +839,9 @@ the result is an error. To disambiguate these cases, a cast is appropriate: -
+ String literals are implicitly converted between chars, wchars, and dchars as necessary. @@ -875,9 +850,7 @@ Strings a single character in length can also be exactly converted to a char, wchar or dchar constant: -
+ printf() and Strings@@ -897,21 +870,17 @@ to use printf() with D strings. The first is to add a terminating 0, and cast the result to a char*: -
+ The second way is to use the precision specifier. The way D arrays are laid out, the length comes first, so the following works: -
+ In the future, it may be necessary to just add a new format specifier to printf() instead of relying on an implementation @@ -965,36 +934,30 @@ Associative arrays are declared by placing the KeyType within the [] of an array declaration: -
+ Particular keys in an associative array can be removed with the remove function: -
+ The InExpression yields a pointer to the value if the key is in the associative array, or null if not: -
+ KeyTypes cannot be functions or voids. @@ -1004,18 +967,14 @@ data within the struct value. A custom mechanism can be used by providing the following functions as struct members: -
+ For example: -
+ Properties@@ -1075,9 +1034,7 @@Associative Array Example: word count-
+ + |
+
Home
| Search
| D
+| Comments
|
+
+ +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Attributes-
+ Attributes are a way to modify one or more declarations. The general forms are: @@ -125,9 +184,7 @@ Linkage Attribute-
+ D provides an easy way to call C functions and operating system API functions, as compatibility with both is essential. @@ -154,35 +211,27 @@ C function calling conventions are specified by: -
+ D conventions are: -
+ or: -
+ Windows API conventions are: -
+ Align Attribute-
+ Specifies the alignment of struct members. align by itself sets it to the default, which matches the default member alignment @@ -212,27 +259,23 @@ Matching the behavior of the companion C compiler can have some surprising results, such as the following for Digital Mars C++: -
+ } AlignAttribute is meant for C ABI compatiblity, which is not the same thing as binary compatibility across diverse platforms. For that, use packed structs: -
+ } A value of 1 means that no alignment is done; members are packed together. @@ -258,14 +301,12 @@ if any code refers to deprecated declarations: -
+ Implementation Note: The compiler should have a switch specifying if deprecated declarations should be compiled with @@ -309,33 +350,27 @@ Const Attribute-
+ The const attribute declares constants that can be evaluated at compile time. For example: -
+ A const declaration without an initializer must be initialized in a constructor (for class fields) or in a static constructor (for static class members, or module variable declarations). -
+ It is not an error to have const module variable declarations without initializers if there is no constructor. This is to support the practice @@ -387,11 +422,9 @@ Override Attribute-
+ The override attribute applies to virtual functions. It means that the function must override a function with the @@ -400,9 +433,7 @@ gets its parameters changed, and all derived classes need to have their overriding functions updated. -
+ Static Attribute-
+ The static attribute applies to functions and data. It means that the declaration does not apply to a particular @@ -433,9 +462,7 @@ other words, it means there is no this reference. static is ignored when applied to other declarations. -
+ Static functions are never virtual. @@ -462,22 +489,18 @@ to a file. Use the private attribute in D to achieve that. For example: -
+ Auto Attribute-
+ The auto attribute is used for local variables and for class declarations. For class declarations, the auto attribute creates @@ -523,15 +546,15 @@ they can still provide 'base class functionality.' + |
+
Home
| Search
| D
+| Comments
|
+
+ + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
D Change Log
+ + What's New for + D 0.130 ++ +Sep 6, 2005 ++ + New/Changed Features+
Bugs Fixed+
What's New for D 0.129 @@ -330,7 +452,7 @@New/Changed Features
|
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Classes@@ -61,9 +122,7 @@ A class declaration is defined: -
+ Classes consist of: @@ -138,33 +197,27 @@ A class is defined: -
+ Note that there is no trailing ; after the closing } of the class definition. It is also not possible to declare a variable var like: -
+ Instead: -
+ Fields@@ -194,9 +247,7 @@ type of the class, not expressions which produce the type of the field itself: -
+ Super Class@@ -219,12 +270,10 @@Constructors-
+ Members are always initialized to the default initializer for their type, which is usually 0 for integer types and @@ -236,16 +285,14 @@ there can be a static initializer to be used instead of the default: -
+ This static initialization is done before any constructors are called. @@ -254,9 +301,7 @@ Constructors are defined with a function name of this and having no return value: -
+ Base class construction is done by calling the base class constructor by the name super: -
+ Constructors can also call other constructors for the same class in order to share common initializations: -
+ If no call to constructors via this or super appear in a constructor, and the base class has a constructor, a call @@ -317,11 +358,9 @@ If there is no constructor for a class, but there is a constructor for the base class, a default constructor of the form: -
+ is implicitly generated. @@ -331,20 +370,16 @@
|
+
Home
| Search
| D
+| Comments
|
+
+ + +D vs C/C++/C#/Java +Rationale for Builtins +Converting C to D +Converting C++ to D +The C Preprocessor vs D +D strings vs C++ std::string +D complex vs C++ std::complex +D Contract Programming vs C++ + + |
+
+
D vs Other Languages@@ -822,15 +860,15 @@ If I've made any errors in this table, please contact me so I can correct them: + |
+
Home
| Search
| D
+| Comments
|
+
+ + +D vs C/C++/C#/Java +Rationale for Builtins +Converting C to D +Converting C++ to D +The C Preprocessor vs D +D strings vs C++ std::string +D complex vs C++ std::complex +D Contract Programming vs C++ + + |
+
+
D Complex Types and C++ std::complex@@ -48,74 +86,60 @@ In C++, the complex types are: -
+ C++ has no distinct imaginary type. D has 3 complex types and 3 imaginary types: -
+ A C++ complex number can interact with an arithmetic literal, but since there is no imaginary type, imaginary numbers can only be created with the constructor syntax: -
+ In D, an imaginary numeric literal has the 'i' suffix. The corresponding code would be the more natural: -
+ For more involved expressions involving constants: -
+ In C++, this would be: -
+ or if an imaginary class were added to C++ it might be: -
+ In other words, an imaginary number nn can be represented with just nni rather than writing a constructor call @@ -128,39 +152,31 @@ on the 0 real part. For example, adding two imaginary numbers in D is one add: -
+ In C++, it is two adds, as the real parts get added too: -
+ Multiply is worse, as 4 multiplies and two adds are done instead of one multiply: -
+ Divide is the worst - D has one divide, whereas C++ implements complex division with typically one comparison, 3 divides, 3 multiplies and 3 additions: -
+ To avoid these efficiency concerns in C++, one could simulate an imaginary number using a double. For example, given the D: -
+ it could be written in C++ as: -
+ but then the advantages of complex being a library type integrated in with the arithmetic operators have been lost. @@ -256,15 +268,15 @@ 7 in The State of the Art in Numerical Analysis (1987) ed. by M. Powell and A. Iserles for Oxford U.P. + |
+
Home
| Search
| D
+| Comments
|
+
+ + +D vs C/C++/C#/Java +Rationale for Builtins +Converting C to D +Converting C++ to D +The C Preprocessor vs D +D strings vs C++ std::string +D complex vs C++ std::complex +D Contract Programming vs C++ + + |
+
+
D's Contract Programming vs C++'s@@ -119,9 +157,7 @@ Consider a class invariant in D: -
+ To accomplish the equivalent in C++ (thanks to Bob Bell for providing this): -
+ There's an additional complication with A::foo(). Upon every normal exit from the function, the invariant() should be called. This means that code that looks like: -
+ would need to be written as: -
+ Or recode the function so it has a single exit point. One possibility to mitigate this is to use RAII techniques: -
+ The #if DBC is still there because some compilers may not optimize the whole thing away if check_invariants compiles to nothing. @@ -264,9 +292,7 @@ Consider the following in D: -
+ This is nicely handled in C++ with the nested Sentry struct: -
+ If the preconditions and postconditions consist of nothing more than assert macros, the whole doesn't need to @@ -301,9 +325,7 @@ to walk the array and verify that it really is sorted. Now the shebang needs to be wrapped in #ifdef: -
+ (One can make use of the C++ rule that templates are only instantiated when used can be used to avoid the #ifdef, by @@ -325,9 +347,7 @@ Let's add a return value to foo() that needs to be checked in the postconditions. In D: -
+ In C++: -
+ Now add a couple parameters to foo(). In D: -
+ In C++: -
+ Preconditions and Postconditions for Member FunctionsConsider the use of preconditions and postconditions for a polymorphic function in D: -
+ The semantics for a call to B.foo() are: @@ -460,9 +472,7 @@ Let's get this to work in C++: -
+ Something interesting has happened here. The preconditions can no longer be done using assert, since the results need @@ -552,15 +562,15 @@ Bjarne Stroustrup, Addison-Wesley + |
+
Home
| Search
| D
+| Comments
|
+
+ + +D vs C/C++/C#/Java +Rationale for Builtins +Converting C to D +Converting C++ to D +The C Preprocessor vs D +D strings vs C++ std::string +D complex vs C++ std::complex +D Contract Programming vs C++ + + |
+
+
D Strings vs C++ Strings@@ -75,111 +113,91 @@ is overloadable. So the C++ string class cannot consistently handle arbitrary expressions containing strings. Consider: -
+ That isn't going to work. But it does work when the core language knows about strings: -
+ Consistency With C String SyntaxThere are three ways to find the length of a string in C++: -
+ That kind of inconsistency makes it hard to write generic templates. Consider D: -
+ Checking For Empty StringsC++ strings use a function to determine if a string is empty: -
+ In D, an empty string has zero length: -
+ Resizing Existing StringC++ handles this with the resize() member function: -
+ D takes advantage of knowing that str is a string, and so resizing it is just changing the length property: -
+ Slicing a StringC++ slices an existing string using a special constructor: -
+ D has the array slice syntax, not possible with C++: -
+ Slicing, of course, works with any array in D, not just strings. @@ -187,46 +205,38 @@ C++ copies strings with the replace function: -
+ D uses the slice syntax as an lvalue: -
+ Conversions to C StringsThis is needed for compatibility with C API's. In C++, this uses the c_str() member function: -
+ In D, strings can be implicitly converted to char*: -
+ Note: some will argue that it is a mistake in D to have an implicit conversion from char[] to char*. @@ -243,16 +253,14 @@ by adding more to the library. In D, they take the obvious syntactical forms: -
+ where str can be any of literal "string"s, fixed string arrays like char[10], or dynamic strings like char[]. A quality implementation @@ -263,21 +271,17 @@ In C++, this is done with the replace() member function: -
+ In D, use the array slicing syntax in the natural manner: -
+ Value vs Reference@@ -324,9 +328,7 @@ Let's take a look at a small utility, wordcount, that counts up the frequency of each word in a text file. In D, it looks like this: -
+ Two people have written C++ implementations using the C++ standard template library, @@ -525,9 +527,7 @@ wccpp2 by Allan Odgaard-
+ + |
+
Home
| Search
| D
+| Comments
|
+
+ +D vs C/C++/C#/Java +Rationale for Builtins +Converting C to D +Converting C++ to D +The C Preprocessor vs D +D strings vs C++ std::string +D complex vs C++ std::complex +D Contract Programming vs C++ + + |
+
+
Programming in D for C++ Programmers@@ -81,25 +119,21 @@ Constructors have the same name as the class: -
+ }; The D WayConstructors are defined with the this keyword: -
+ } which reflects how they are used in D. @@ -110,9 +144,7 @@ Base constructors are called using the base initializer syntax. -
+ }; The D WayThe base class constructor is called with the super syntax: -
+ } It's superior to C++ in that the base constructor call can be flexibly placed anywhere in the derived constructor. D can also have one constructor call another one: -
+ } Members can also be initialized to constants before the constructor is ever called, so the above example is equivalently written as: -
+ } Comparing structs@@ -180,20 +206,16 @@ While C++ defines struct assignment in a simple, convenient manner: -
+ it does not for struct comparisons. Hence, to compare two struct instances for equality: -
+ Note that the operator overload must be done for every struct needing to be compared, and the implementation of that overloaded @@ -236,14 +258,12 @@ D does it the obvious, straightforward way: -
+ Creating a new typedef'd type@@ -254,9 +274,7 @@ a new type. The compiler doesn't distinguish between a typedef and its underlying type. -
+ The C++ solution is to create a dummy struct whose sole purpose is to get type checking and overloading on the new type. -
+ The D WayNo need for idiomatic constructions like the above. Just write: -
+ Note how a default initializer can be supplied for the typedef as a value of the underlying type. @@ -323,9 +337,7 @@ but need to access each other's private members. This is done using friend declarations: -
+ The D Way@@ -360,9 +372,7 @@ in the same module, so implicitly granting friend access to other module members solves the problem neatly: -
+ The private attribute prevents other modules from accessing the members. @@ -398,9 +408,7 @@ it's convenient to overload the comparison operators so it can be compared against integers: -
+ A total of 8 functions are necessary. @@ -422,14 +430,12 @@ D recognizes that the comparison operators are all fundamentally related to each other. So only one function is necessary: -
+ The compiler automatically interprets all the <, <=, > and >= @@ -451,24 +457,20 @@ A using-declaration in C++ is used to bring a name from a namespace scope into the current scope: -
+ The D WayD uses modules instead of namespaces and #include files, and alias declarations take the place of using declarations: -
+ Alias is a much more flexible than the single purpose using declaration. Alias can be used to rename symbols, refer to @@ -492,9 +494,7 @@ leaving a scope, RAII is implemented by putting the resource release code into the destructor: -
+ The D Way@@ -517,9 +517,7 @@ The few RAII issues left are handled by auto classes. Auto classes get their destructors run when they go out of scope. -
+ Properties@@ -548,9 +546,7 @@ along with object-oriented get and set functions for it: -
+ All this is quite a bit of typing, and it tends to make code unreadable by filling @@ -575,9 +571,7 @@ Properties can be get and set using the normal field syntax, yet the get and set will invoke methods instead. -
+ which is used as: -
+ Thus, in D a property can be treated like it was a simple field name. A property can start out actually being a simple field name, @@ -621,9 +613,7 @@ them, relying on specialization to end it. A template to compute a factorial would be: -
+ } The D Way@@ -647,9 +637,7 @@ advantage of promotion of single template members to the enclosing name space: -
+ } @@ -697,9 +685,7 @@ A preprocessor macro is also needed to make up for the lack of template typedefs. -
+ } The D Way@@ -762,9 +748,7 @@ It compiles quickly, and gives a sensible compile time message if it fails. -
+ } @@ -805,9 +789,7 @@ pg. 353 which determines if the template's argument type is a function: -
+ This template relies on the SFINAE @@ -837,9 +819,7 @@ SFINAE can be done in D without resorting to template argument pattern matching: -
+ The task of discovering if a type is a function doesn't need a template at all, nor does it need the subterfuge of attempting to @@ -862,27 +842,25 @@ The is expression can test it directly: -
+ + |
+
Home
| Search
| D
+| Comments
|
+
+ +D vs C/C++/C#/Java +Rationale for Builtins +Converting C to D +Converting C++ to D +The C Preprocessor vs D +D strings vs C++ std::string +D complex vs C++ std::complex +D Contract Programming vs C++ + + |
+
+
Programming in D for C Programmers@@ -109,23 +147,19 @@The C Way-
+ sizeof(struct Foo) The D WayUse the size property: -
+ Foo.size @@ -133,26 +167,22 @@ The C Way-
+ The D Way-
+ @@ -160,9 +190,7 @@ C to D types-
+ Although char is an unsigned 8 bit type, and wchar is an unsigned 16 bit type, they have their own separate types @@ -195,9 +223,7 @@ The C Way-
+ The D Way-
+ Remainder after division of floating point numbersThe C Way-
+ The D WayD supports the remainder ('%') operator on floating point operands: -
+ @@ -265,26 +285,22 @@ is NAN, and few C compilers check for it (the Digital Mars C compiler is an exception, DM's compilers do check for NAN operands). -
+ The D WayD offers a full complement of comparisons and operators that work with NAN arguments. -
+ result = (x < y); // false if x or y is nan + @@ -296,23 +312,19 @@ and __LINE__ from which an assert macro can be built. In fact, there appears to be practically no other use for __FILE__ and __LINE__. -
+ The D WayD simply builds assert into the language: -
+ [NOTE: trace functions?] @@ -322,23 +334,19 @@ The C Way-
+ The D Way-
+ @@ -349,46 +357,38 @@ The array length is defined separately, or a clumsy sizeof() expression is used to get the length. -
+ or: -
+ The D WayThe length of an array is accessible the property "length". -
+ or even better: -
+ @@ -401,9 +401,7 @@ variable for the length, and then explicitly manage the size of the array: -
+ The D WayD supports dynamic arrays, which can be easily resized. D supports all the requisite memory management. -
+ @@ -442,9 +438,7 @@ when can storage be free'd, dealing with null pointers, finding the length of the strings, and memory allocation: -
+ The D WayD overloads the operators ~ and ~= for char and wchar arrays to mean concatenate and append, respectively: -
+ @@ -500,25 +492,21 @@ printf() is the general purpose formatted print routine: -
+ The D WayWhat can we say? printf() rules: -
+ @@ -530,9 +518,7 @@ not yet encountered in the source file, it is necessary to insert a function declaration lexically preceding the call. -
+ The D Way@@ -554,9 +540,7 @@ referenced function declarations twice. Functions can be defined in any order. -
+ @@ -574,11 +558,9 @@ The C Way-
+ The D Way@@ -586,14 +568,12 @@ say a function takes no arguments, just don't declare it has having arguments. -
+ @@ -604,9 +584,7 @@ Break's and continue's only apply to the innermost nested loop or switch, so a multilevel break must use a goto: -
+ The D Way@@ -629,9 +607,7 @@ is the label for an enclosing loop or switch, and the break applies to that loop. -
+ @@ -670,22 +646,18 @@ It's annoying to have to put the struct keyword every time a type is specified, so a common idiom is to use: -
+ The D WayStruct tag names are not in a separate name space, they are in the same name space as ordinary names. Hence: -
+ @@ -697,9 +669,7 @@ values and take action based on which one it is. A typical use for this might be command line argument processing. -
+ The problem with this is trying to maintain 3 parallel data structures, the enum, the table, and the switch cases. If there @@ -740,9 +710,7 @@ strings as well as numbers. Then, the way to code the string lookup becomes straightforward: -
+ Adding new cases becomes easy. The compiler can be relied on to generate a fast lookup scheme for it, eliminating the bugs @@ -769,16 +737,14 @@ program, and woe results if any modules or libraries didn't get recompiled. To address this, #pragma's are used: -
+ But #pragmas are nonportable both in theory and in practice from compiler to compiler. @@ -788,9 +754,7 @@ Clearly, since much of the point to setting alignment is for portability of data, a portable means of expressing it is necessary. -
+ @@ -817,9 +781,7 @@ C doesn't allow anonymous structs or unions, which means that dummy tag names and dummy members are necessary: -
+ Not only is it clumsy, but using macros means a symbolic debugger won't understand what is being done, and the macros have global scope instead of struct scope. @@ -849,9 +811,7 @@ Anonymous structs and unions are used to control the layout in a more natural manner: -
+ @@ -877,31 +837,25 @@ Is to do it in one statement ending with a semicolon: -
+ Or to separate the two: -
+ The D WayStruct definitions and declarations can't be done in the same statement: -
+ which means that the terminating ; can be dispensed with, eliminating the confusing difference between struct {} and function & block {} in how semicolons @@ -915,26 +869,22 @@ Naturally, another macro is used: -
+ The D WayAn offset is just another property: -
+ @@ -944,12 +894,10 @@ Unions are initialized using the "first member" rule: -
+ Adding union members or rearranging them can have disastrous consequences for any initializers. @@ -958,12 +906,10 @@ In D, which member is being initialized is mentioned explicitly: -
+ avoiding the confusion and maintenance problems. @@ -975,12 +921,10 @@ Members are initialized by their position within the {}'s: -
+ This isn't much of a problem with small structs, but when there are numerous members, it becomes tedious to get the initializers @@ -992,12 +936,10 @@ Member initialization can be done explicitly: -
+ The meaning is clear, and there no longer is a positional dependence. @@ -1008,46 +950,36 @@ The C WayC initializes array by positional dependence: -
+ Nested arrays may or may not have the { }: -
+ The D WayD does it by positional dependence too, but an index can be used as well: The following all produce the same result: -
+ This can be handy if the array will be indexed by an enum, and the order of enums may be changed or added to: -
+ Nested array initializations must be explicit: -
+ @@ -1056,40 +988,30 @@ The C WayC has problems with the DOS file system because a \ is an escape in a string. To specifiy file c:\root\file.c: -
+ This gets even more unpleasant with regular expressions. Consider the escape sequence to match a quoted string: -
+ In C, this horror is expressed as: -
+ The D WayWithin strings, it is WYSIWYG (what you see is what you get). Escapes are in separate strings. So: -
+ The famous hello world string becomes: -
+ @@ -1100,30 +1022,24 @@ The C WayC uses the wchar_t and the L prefix on strings: -
+ Things get worse if code is written to be both ascii and wchar compatible. A macro is used to switch strings from ascii to wchar: -
+ The D WayThe type of a string is determined by semantic analysis, so there is no need to wrap strings in a macro call: -
+ @@ -1132,18 +1048,14 @@ The C WayConsider: -
+ This is fairly easy to get right because the number of entries is small. But suppose it gets to be fairly large. Then it can get difficult to maintain correctly when new entries are added. The D Way-
+ Not perfect, but better. @@ -1166,9 +1078,7 @@ a new type. The compiler doesn't distinguish between a typedef and its underlying type. -
+ The C solution is to create a dummy struct whose sole purpose is to get type checking and overloading on the new type. -
+ Having a default value for the type involves defining a macro, a naming convention, and then pedantically following that convention: -
+ For the struct solution, things get even more complex: -
+ There are 4 names to remember: Handle, HANDLE_INIT, struct Handle__, value. @@ -1233,9 +1137,7 @@ No need for idiomatic constructions like the above. Just write: -
+ To handle a default value, add an initializer to the typedef, and refer to it with the .init property: -
+ There's only one name to remember: Handle. @@ -1268,27 +1168,23 @@ While C defines struct assignment in a simple, convenient manner: -
+ it does not for struct comparisons. Hence, to compare two struct instances for equality: -
+ Note the obtuseness of this, coupled with the lack of any kind of help from the language with type checking. @@ -1304,14 +1200,12 @@ D does it the obvious, straightforward way: -
+ @@ -1320,14 +1214,12 @@ The C WayThe library function strcmp() is used: -
+ C uses 0 terminated strings, so the C way has an inherent inefficiency in constantly scanning for the terminating 0. @@ -1336,14 +1228,12 @@ Why not use the == operator? -
+ D strings have the length stored separately from the string. Thus, the implementation of string compares can be much faster @@ -1353,14 +1243,12 @@ D supports comparison operators on strings, too: -
+ which is useful for sorting/searching. @@ -1372,9 +1260,7 @@ Although many C programmers tend to reimplmement bubble sorts over and over, the right way to sort in C is to use qsort(): -
+ A compare() must be written for each type, and much careful typo-prone code needs to be written to make it work. @@ -1397,13 +1283,11 @@ Sorting couldn't be easier: -
+ Volatile memory access@@ -1412,25 +1296,21 @@ To access volatile memory, such as shared memory or memory mapped I/O, a pointer to volatile is created: -
+ The D WayD has volatile as a statement type, not as a type modifier: -
+ String literals@@ -1440,13 +1320,11 @@ String literals in C cannot span multiple lines, so to have a block of text it is necessary to use \ line splicing: -
+ If there is a lot of text, this can wind up being tedious. @@ -1454,14 +1332,12 @@ String literals can span multiple lines, as in: -
+ So blocks of text can just be cut and pasted into the D source. @@ -1485,9 +1361,7 @@ some context outside of the trees, so a custom struct Paramblock is created and a pointer to it is used to maximize efficiency. -
+ The D Way@@ -1543,9 +1417,7 @@ The performance of the two versions is indistinguishable. -
+ Unsigned Right Shift@@ -1591,24 +1463,20 @@ integral type. To produce an unsigned right shift on an int, a cast is necessary: -
+ If i is an int, this works fine. But if i is of a typedef'd type, -
+ and myint happens to be a long int, then the cast to unsigned @@ -1623,13 +1491,11 @@ do an unsigned right shift regardless of the sign of the left operand. Hence, -
+ avoids the unsafe cast and will work as expected with any integral type. @@ -1651,9 +1517,7 @@ class that holds an array of int's, and a user of that container that computes the maximum of those int's. -
+ The C way makes heavy use of pointers and casting. The casting is tedious, error prone, and loses all type safety. @@ -1691,9 +1555,7 @@ and nested functions both to capture context information and to improve locality. -
+ } Pointers are eliminated, as well as casting and generic pointers. The D version is fully type safe. An alternate method in D makes use of function literals: -
+ } eliminating the need to create irrelevant function names. @@ -1741,9 +1601,7 @@ The C Way-
+ There are two problems with this. The first is that the sum function needs to know how many arguments were @@ -1787,9 +1645,7 @@ type, and the number of arguments becomes a property of the array: -
+ + |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Contract Programming@@ -77,11 +138,9 @@ assert. An assert inserts a checkable expression into the code, and that expression must evaluate to true: -
+
C programmers will find it familiar. Unlike C, however, an
+
By definition, if a pre contract fails, then the body received bad parameters.
An InException is thrown. If a post contract fails,
then there is a bug in the body. An OutException is thrown.
@@ -122,9 +179,7 @@
body, the variable
+ The assert's in the in and out bodies are called contracts. Any other D statement or expression is allowed in the bodies, but it is important @@ -151,9 +206,7 @@ If the function returns a void, there is no result, and so there can be no result declaration in the out clause. In that case, use: -
+ In an out statement, result is initialized and set to the return value of the function. @@ -173,9 +226,7 @@ The in-out statement can also be used inside a function, for example, it can be used to check the results of a loop: -
+ This is not implemented at this time. In, Out and Inheritance@@ -211,26 +262,22 @@ A function can specify the errors it can generate. Since the D way to handle errors is via exceptions, a function declaration lists the exceptions it can generate with the exception specification: -
+ If there is no exception specification, a function can throw any exception. If there is an empty exception specification: -
+
then the function is defined to not throw any exceptions. If a function
throws an exception when it is defined to not throw any exceptions,
the program will be aborted.
@@ -253,15 +300,15 @@
Contracts Reading List |
+
Home
| Search
| D
+| Comments
|
+
+ + + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
Compiler for D Programming Language@@ -555,15 +625,15 @@ and most especially donated code! Join the fray in the D forum. + |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
+
+Declarations+ ++Declaration: + typedef Decl + alias Decl + Decl + +Decl: + StorageClass Decl + BasicType Declarators ; + BasicType Declarator FunctionBody + +Declarators: + DeclaratorInitializer + DeclaratorInitializer , DeclaratorIdentifierList + +DeclaratorInitializer: + Declarator + Declarator = Initializer + +DeclaratorIdentifierList: + DeclaratorIdentifier + DeclaratorIdentifier , DeclaratorIdentifierList + +DeclaratorIdentifier: + Identifier + Identifier = Initializer + +BasicType: + bit + byte + ubyte + short + ushort + int + uint + long + ulong + char + wchar + dchar + float + double + real + ifloat + idouble + ireal + cfloat + cdouble + creal + void + .IdentifierList + IdentifierList + Typeof + Typeof . IdentifierList + +BasicType2: + * + [ ] + [ Expression ] + [ Type ] + delegate ( ParameterList ) + function ( ParameterList ) + +Declarator: + BasicType2 Declarator + Identifier + ( Declarator ) + Identifier DeclaratorSuffixes + ( Declarator ) DeclaratorSuffixes + +DeclaratorSuffixes: + DeclaratorSuffix + DeclaratorSuffix DeclaratorSuffixes + +DeclaratorSuffix: + [ ] + [ Expression ] + [ Type ] + ( ParameterList ) + +IdentifierList: + Identifier + Identifier . IdentifierList + TemplateInstance + TemplateInstance . IdentifierList + +Typeof: + typeof ( Expression ) + +StorageClass: + abstract + auto + const + deprecated + final + override + static + synchronized + +Type: + BasicType + BasicType Declarator2 + +Declarator2: + BasicType2 Declarator2 + ( Declarator2 ) + ( Declarator2 ) DeclaratorSuffixes + +ParameterList: + Parameter + Parameter , ParameterList + ... + +Parameter: + Declarator + Declarator = AssignExpression + InOut Declarator + InOut Declarator = AssignExpression + +InOut: + in + out + inout + +Initializer: + void + AssignExpression + ArrayInitializer + StructInitializer -
+ Declaration Syntax- Declaration syntax generally reads right to left: +Declaration syntax generally reads right to left: + ++int x; // x is an int +int* x; // x is a pointer to int +int** x; // x is a pointer to a pointer to int +int[] x; // x is an array of ints +int*[] x; // x is an array of pointers to ints +int[]* x; // x is a pointer to an array of ints ++ + Arrays read right to left as well: + ++int[3] x; // x is an array of 3 ints +int[3][5] x; // x is an array of 5 arrays of 3 ints +int[3]*[5] x; // x is an array of 5 pointers to arrays of 3 ints ++ + +Pointers to functions are declared using the function keyword: + -
- - Arrays read right to left as well: - -
- - Pointers to functions are declared using the function keyword: - -
- - C-style array declarations may be used as an alternative: - -
- - In a declaration declaring multiple symbols, all the declarations - must be of the same type: - -
+int function(char)[] x; // x is an array of pointers to functions + // taking a char argument and returning an int + + + +C-style array declarations may be used as an alternative: + + ++int x[3]; // x is an array of 3 ints +int x[3][5]; // x is an array of 3 arrays of 5 ints +int (*x[5])[3]; // x is an array of 5 pointers to arrays of 3 ints +int (*x)(char); // x is a pointer to a function taking a char argument + // and returning an int +int (*[] x)(char); // x is an array of pointers to functions + // taking a char argument and returning an int ++ + +In a declaration declaring multiple symbols, all the declarations +must be of the same type: + + ++int x,y; // x and y are ints +int* x,y; // x and y are pointers to ints +int x,*y; // error, multiple types +int[] x,y; // x and y are arrays of ints +int x[],y; // error, multiple types +- Type Defining+Type Defining+Strong types can be introduced with the typedef. Strong types are semantically a distinct type to the type checking system, for function overloading, and for the debugger. + + +
+typedef int myint;
+
+void foo(int x) { . }
+void foo(myint m) { . }
+
+ .
+myint b;
+foo(b); // calls foo(myint)
+
-
- - Typedefs can specify a default initializer different from the - default initializer of the underlying type: - -
+Typedefs can specify a default initializer different from the +default initializer of the underlying type: + +typedef int myint = 7; +myint m; // initialized to 7 +- Type Aliasing+Type Aliasing+ +It's sometimes convenient to use an alias for a type, such as a shorthand for typing out a long, complex type like a pointer to a function. In D, this is done with the alias declaration: + -
+ +alias abc.Foo.bar myint; ++ Aliased types are semantically identical to the types they are aliased to. The debugger cannot distinguish between them, and there is no difference as far as function overloading is concerned. For example: + + ++alias int myint; -
+void foo(int x) { . } +void foo(myint m) { . } error, multiply defined function foo + + Type aliases are equivalent to the C typedef. + Alias Declarations+A symbol can be declared as an alias of another symbol. For example: + -
+
+import string;
+alias string.strlen mylen;
+ ...
+int len = mylen("hello"); // actually calls string.strlen()
+
+
+ The following alias declarations are valid: + -
+
+template Foo2(T) { alias T t; }
+alias Foo2!(int) t1;
+alias Foo2!(int).t t2;
+alias t1.t t3;
+alias t2 t4;
+
+t1.t v1; // v1 is type int
+t2 v2; // v2 is type int
+t3 v3; // v3 is type int
+t4 v4; // v4 is type int
+
+ Aliased symbols are useful as a shorthand for a long qualified symbol name, or as a way to redirect references from one symbol to another: + -
+
+version (Win32)
+{
+ alias win32.foo myfoo;
+}
+version (linux)
+{
+ alias linux.bar myfoo;
+}
+
+ Aliasing can be used to 'import' a symbol from an import into the current scope: -
+ + ++alias string.strlen strlen; ++ Aliases can also 'import' a set of overloaded functions, that can be overloaded with functions in the current scope: + + +
+class A {
+ int foo(int a) { return 1; }
+}
+
+class B : A {
+ int foo( int a, uint b ) { return 2; }
+}
+
+class C : B {
+ int foo( int a ) { return 3; }
+ alias B.foo foo;
+}
-
+class D : C { +} + +void test() +{ + D b = new D(); + int i; + + i = b.foo(1, 2u); // calls B.foo + i = b.foo(1); // calls C.foo +} + + + Note: Type aliases can sometimes look indistinguishable from alias declarations: -
+ + ++alias foo.bar abc; // is it a type or a symbol? ++ + The distinction is made in the semantic analysis pass. + -typeof+typeof+Typeof is a way to specify a type based on the type of an expression. For example: + -
+
+void func(int i)
+{
+ typeof(i) j; // j is of type int
+ typeof(3 + 6.0) x; // x is of type double
+ typeof(1)* p; // p is of type pointer to int
+ int[typeof(p)] a; // a is of type int[int*]
+
+ printf("%d\n", typeof('c').sizeof); // prints 1
+ double c = cast(typeof(1.0))j; // cast j to double
+}
+
+ Expression is not evaluated, just the type of it is generated: + -
+
+void func()
+{ int i = 1;
+ typeof(++i) j; // j is declared to be an int, i is not incremented
+ printf("%d\n", i); // prints 1
+}
+
+ There are two special cases: typeof(this) will generate the type of what this would be in a non-static member function, even if not in a member function. Analogously, typeof(super) will generate the type of what super would be in a non-static member function. + + +
+class A { }
-
+typeof(this) r; // error, no enclosing struct or class + + Where Typeof is most useful is in writing generic template code. + + |
+
Home
| Search
| D
+| Comments
|
+
+ + + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
D Links@@ -424,15 +494,15 @@ the links to Digital Mars.+ |
+
Home
| Search
| D
+| Comments
|
+
+ + + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
Writing Win32 DLLs in D@@ -72,9 +142,7 @@ A DllMain() is required, looking like: -
+ Notes:
mydll2.d:-
+ mydll.def:@@ -176,9 +242,7 @@ Now for a program, test.d, which will use the dll:
+ Create a clone of mydll2.d that doesn't have the function bodies: mydll.d:-
+ Compile and link with the command: @@ -276,9 +338,7 @@ So, to write a COM object: -
+ The sample code includes an example COM client program and server DLL. @@ -313,9 +373,7 @@ Starting with the code for the DLL, mydll.d: -
+
|
+
+
+Home
+| Search
+| D
+| Comments
+
+|
+
+ + + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
+
+Embedded Documentation+ + +The D programming language enables embedding both contracts and test +code along side the actual code, which helps to keep them all +consistent with each other. One thing lacking is the documentation, +as ordinary comments are usually unsuitable for automated extraction +and formatting into manual pages. +Embedding the user documentation into the source code has important +advantages, such as not having to write the documentation twice, and +the likelihood of the documentation staying consistent with the code. ++ +Some existing approaches to this are: + +
Specification+ +Note: This is not implemented, it's just a proposal. ++ +Embedded documentation comments are one of the following forms: + +
+/// This is a one line documentation comment. + +/** So is this. */ + +/++ And this. +/ + +/** + This is a brief documentation comment. + */ + +/** + * The leading * on this line is not part of the documentation comment. + */ + +/********************************* + The extra *'s immediately following the /** are not + part of the documentation comment. + */ + +/++ + This is a brief documentation comment. + +/ + +/++ + + The leading + on this line is not part of the documentation comment. + +/ + +/+++++++++++++++++++++++++++++++++ + The extra +'s immediately following the /++ are not + part of the documentation comment. + +/ + ++ +The extra *'s and +'s on the comment opening and left margin are ignored +and are not part +of the embedded documentation. +Comments not following one of those forms are not documentation comments. + + +Each documentation comment is associated with a declaration. +If the documentation comment is on a line by itself or with only whitespace +to the left, it refers to the next +declaration. +Multiple documentation comments with no intervening declarations +are concatenated. +Documentation comments preceding the ModuleDeclaration apply to the +entire module. +If the documentation comment appears on the same line to the right of a +declaration, it applies to that. +A documentation comment before the ModuleDeclaration applies to the +entire module. + +If a documentation comment for a declaration consists only of the +identifier ditto +then the documentation comment for the previous declaration at the same +scope is applied to this declaration as well. + + +
+int a; /// documentation for a; b has no documentation
+int b;
+
+/** documentation for c and d */
+/** more documentation for c and d */
+int c;
+/** ditto */
+int d;
+
+/** documentation for e and f */ int e;
+int f; /// ditto
+
+/// documentation for C and D
+class C
+{
+ int x; /// documentation for C.x
+
+ /** documentation for C.y and C.z */
+ int y;
+ int z; /// ditto
+}
+
+/// ditto
+class D
+{
+}
+
+
+
+
+Basic Structure+ +The first paragraph, up to a blank line or a Section, +of a documentation comment forms the +summary line. Summary lines should be short. +Subsequent paragraphs form the more detailed description. +Paragraphs are delineated by blank lines or Sections. + +
+/***********************************
+ * Brief summary of what
+ * myfunc does.
+ *
+ * First paragraph of fuller description.
+ *
+ * Second paragraph of
+ * fuller description.
+ */
+
+void myfunc() { }
+
+
+Function parameters can be documented by associating a comment with each
+parameter:
+
+
+/***********************************
+ * foo does this.
+ */
+
+void foo(
+ int x, /// is for this
+ int y /// is for that
+ )
+{
+}
+
+
+
+Hyperlinks+ +Hyperlinks and email addresses can just be inserted as is, the documentation +extractor will convert them into HTML hyperlinks as necessary: + ++/** For more information mail to foo@bar.com or look + at the website http://www.bar.com. + */ ++ + + Embedded HTML+ +HTML can be embedded into the documentation comments, and it will +be passed through to the HTML output unchanged. +However, since it is not necessarily true that HTML will be the desired +output format of the embedded documentation comment extractor, it is +best to avoid using it where practical. + ++/** Example of embedded HTML: + * <ol> + * <li> <a href="www.digitalmars.com">Digital Mars</a> + * <li> <a href="www.classicempire.com">Empire</a> + * </ol> + */ ++ + + Emphasis+ +Identifiers in documentation comments that are function parameters or are +names that are in scope at the associated declaration are emphasized in +the output. +This emphasis can take the form of italics, boldface, a hyperlink, etc. +How it is emphasized depends on what it is - a function parameter, type, +D keyword, etc. +To prevent unintended emphasis of an identifier, it can be preceded by +an underscore (_). The underscore will be stripped from the output. + +Sections+ +Additional, more specific information can be delineated with Sections. +Sections start with an identifier being the first non-whitespace on a +line, immediately followed by a colon ":". +They are optional and case-insensitive. +The section continues until either the end of the documentation comment +or another section. +Unrecognized sections are passed through to the output unchanged. + +Author:+ +Specifies the name of the author. + ++/** + * Author: Melvin D. Nerd + */ ++ + + Code:+ +Used for embedding example D code. Because D code can contain comments, +the /++ ... +/ should probably be the documentation comment used for +code sections. + +
+/+++++++++++++++++++++++++
+ + Code:
+ + int func()
+ + {
+ + return 3; /* the value */
+ + }
+ +/
+
+
+
+Date:+ +Specifies the date of the last revision. The date should be in a form +parseable by std.date. + ++/** + * Date: March 14, 2003 + */ ++ + + Deprecated:+ +Provides an explanation for and corrective action to take if the associated +declaration is marked as deprecated. + +
+/**
+ * Deprecated: superseded by function bar().
+ */
+
+deprecated void foo() { ... }
+
+
+
+Include:+ +Specifies a file to be inserted verbatim into the output +of the documentation processor. The file can contain additional documentation, +or things like boilerplate. + ++/** + * Include: boilerplate.txt + */ ++ + + License:+ +Specifies the license. + +Keywords:+ +Keywords are added to the list of identifiers to be emphasized. +They only apply to the current documentation comments or to +documentation comments nested within the scope of the associated declaration. + +
+/**
+ * This cow will be emphasized.
+ * Keywords: fread, fwrite, cow
+ */
+class A
+{
+ /** A, x and cow will be emphasized */
+ int x;
+}
+
+/**
+ * This cow won't be emphasized.
+ */
+class B { }
+
+
+
+Params:+ +This is an alternate method of documenting a function's parameters. +The first identifier of each subsequent line is taken to be a parameter name, +followed by its description. Multiple description lines are lined up with +the start of the first description line. + +
+/** This is my function.
+ * Params:
+ * fp File pointer
+ * name File name and
+ * more.
+ */
+
+void foo(FILE *fp, char[] name)
+{
+ ..
+}
+
+
+
+Returns:+ +Explains the return value of the function. +If the function returns void, don't redundantly document it. + +
+/**
+ * Read the file.
+ * Returns: The contents of the file.
+ */
+
+void[] readFile(char[] filename) { ... }
+
+
+
+URL:+ +In order for hyperlinks to symbols outside of the current module, +the documentation extractor must know the URL where they will be +located. The URL section is a list of pairs of module names and URL +prefixes. + ++import std.string; +/** + * Thid identifier toupper will be replaced by a hyperlink to + * http://www.digitalmars.com/d/phobos/std_string.html#toupper. + * + * URL: + * std.string http://www.digitalmars.com/d/phobos/std_string.html + */ ++ + + Version:+ +Specifies the version. + ++/** + * Version: 1.6a + */ ++ + + + |
Add feedback and comments regarding this + page.
+ +
Home
| Search
| D
+| Comments
|
+
+ + + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
The D Style@@ -70,30 +140,24 @@
+
+ Module names should be all lower case.
+
+
+ should be avoided. @@ -181,21 +235,17 @@ Since in D the declarations are left-associative, left justify them: -
+ to emphasize their relationship. Do not use the C style: -
+ Operator Overloading@@ -211,15 +261,15 @@ Just say no. + |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Named Character Entities@@ -319,15 +380,15 @@ |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Enums - Enumerated Types@@ -150,15 +211,15 @@ X x; // x is initialized to 3 + |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Error Handling in D@@ -242,15 +303,15 @@ --> + |
+
Home
| Search
| D
+| Comments
|
+
+ +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Expressions@@ -50,9 +111,7 @@ These values can then be assigned, tested, or ignored. Expressions can also have side effects. -
+ Evaluation Order@@ -217,13 +276,11 @@ the components of an expression in any order. It is an error to depend on order of evaluation when it is not specified. For example, the following are illegal: -
+ If the compiler can determine that the result of an expression is illegally dependent on the order of evaluation, it can issue an error (but is not required to). The ability to detect these kinds @@ -231,11 +288,9 @@ Expressions-
+ The left operand of the , is evaluated, then the right operand is evaluated. The type of the expression is the type of the right @@ -244,11 +299,9 @@ Assign Expressions-
+ The right operand is implicitly converted to the type of the left operand, and assigned to it. The result type is the type @@ -260,9 +313,7 @@ Assignment Operator Expressions-
+ Assignment operator expressions, such as: @@ -292,11 +343,9 @@ Conditional Expressions-
+ The first expression is converted to bool, and is evaluated. If it is true, then the second expression is evaluated, and @@ -310,11 +359,9 @@ OrOr Expressions-
+ The result type of an OrOr expression is bool, unless the right operand has type void, when the result is type void. @@ -336,11 +383,9 @@ AndAnd Expressions-
+ The result type of an AndAnd expression is bool, unless the right operand has type void, when the result is type void. @@ -369,43 +414,35 @@ Or Expressions-
+ The operands are OR'd together. Xor Expressions-
+ The operands are XOR'd together. And Expressions-
+ The operands are AND'd together. Equality Expressions-
+ Equality expressions compare the two operands for equality (==) or inequality (!=). @@ -451,12 +488,10 @@ Identity Expressions-
+ The is compares for identity. To compare for not identity, use e1 !is e2. @@ -482,9 +517,7 @@ Relational Expressions-
+ First, the integral promotions are done on the operands. The result type of a relational expression is bool. @@ -629,22 +662,18 @@ In Expressions-
+ An associative array can be tested to see if an element is in the array: -
+ The in expression has the same precedence as the relational expressions <, <=, @@ -655,13 +684,11 @@ Shift Expressions-
+ The operands must be integral types, and undergo the usual integral promotions. The result type is the type of the left operand after @@ -677,22 +704,18 @@ It's illegal to shift by more bits than the size of the quantity being shifted: -
+ Add Expressions-
+ If the operands are of integral types, they undergo integral promotions, and then are brought to a common type using the @@ -715,13 +738,11 @@ and added to the pointer. It is illegal if the second operand modulo 8 is non-zero. -
+ If the second operand is a pointer, and the first is an integral type, and the operator is +, @@ -733,13 +754,11 @@ Mul Expressions-
+ The operands must be arithmetic types. They undergo integral promotions, and then are brought to a common type using the @@ -763,9 +782,7 @@ Unary Expressions-
+ New Expressions@@ -791,13 +808,11 @@ To allocate multidimensional arrays, the declaration reads in the same order as the prefix array declaration order. -
+ foo = new char[][30]; // allocate array of 30 strings + If there is an ( ArgumentList ), then those arguments are passed to the class or struct specific allocator @@ -825,11 +840,9 @@ There is an ambiguity in the grammar, however. Consider: -
+ Is this a cast of a dereference of negated p to type foo, or is it p being subtracted from foo? This cannot be resolved without looking up foo in the symbol table to see if it is a @@ -840,20 +853,16 @@ C++ does this by introducing: -
+ which is ugly and clumsy to type. D introduces the cast keyword: -
+ cast has the nice characteristic that it is easy to do a textual search for it, and takes some @@ -865,9 +874,7 @@ downcast. This means that it is equivalent to the behavior of the dynamic_cast operator in C++. -
+ In order to determine if an object o is an instance of a class B use a cast: -
+ Postfix Expressions-
+ Index Expressions-
+ PostfixExpression is evaluated. if PostfixExpression is an expression of type @@ -928,11 +929,9 @@ Slice Expressions-
+ PostfixExpression is evaluated. if PostfixExpression is an expression of type @@ -952,9 +951,7 @@ Primary Expressions-
+ .Identifier@@ -983,9 +980,7 @@ If a member function is called with an explicit reference to typeof(this), a non-virtual call is made: -
+ super@@ -1044,9 +1039,7 @@Function Literals-
+ FunctionLiterals enable embedding anonymous functions and anonymous delegates directly into expressions. @@ -1069,9 +1062,7 @@ For example: -
+ is exactly equivalent to: -
+ And: -
+ is exactly equivalent to: -
+ Anonymous delegates can behave like arbitrary statement literals. For example, here an arbitrary statement is executed by a loop: -
+ When comparing with nested functions, the function form is analogous to static @@ -1159,12 +1142,10 @@ Assert Expressions-
+ Asserts evaluate the expression. If the result is false, an AssertError is thrown. If the result is true, then no @@ -1187,21 +1168,17 @@ Typeid Expressions-
+ Returns an instance of class TypeInfo corresponding to Type. IsExpression-
+ IsExpressions are evaluated at compile time and are used for checking for valid types, comparing types for equivalence, @@ -1253,9 +1230,7 @@ The condition is satisfied if Type is semantically correct (it must be syntactically correct regardless). -
+ The condition is satisfied if Type is semantically @@ -1276,9 +1251,7 @@ or can be implicitly converted to TypeSpecialization. TypeSpecialization is only allowed to be a Type. -
+ The condition is satisfied if Type is semantically @@ -1306,9 +1279,7 @@ delegate then the condition is satisifed if Type is one of those. -
+ The condition is satisfied if Type is semantically correct. If so, Identifier is declared to be an alias of Type. -
+ The condition is satisfied if Type is the same as @@ -1357,9 +1326,7 @@ dependent on Identifier, the deduced type. TypeSpecialization is only allowed to be a Type. -
+ The way the type of Identifier is determined is analogous to the way template parameter types are determined by @@ -1434,9 +1401,7 @@ the function type of the delegate
| |
-
+ |
+ +
+
Home
| Search
| D
+| Comments
|
+
+ + + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
FAQ@@ -285,9 +355,7 @@How do I do anonymous struct/unions in D?-
+ How do I get printf() to work with strings?In C, the normal way to printf a string is to use the %s format: -
+ Attempting this in D, as in: -
+ usually results in garbage being printed, or an access violation. The cause is that in C, strings are terminated by a 0 character. The %s format prints until a 0 is encountered. In D, strings are not 0 terminated, the size is determined by a separate length value. So, strings are printf'd using the %.*s format: -
+ which will behave as expected. Remember, though, that printf's %.*s will print until the length is reached or a 0 is encountered, so D strings with embedded 0's @@ -352,11 +414,9 @@ A floating point value, if no explicit initializer is given, is initialized to nan (Not A Number): -
+ Nan's have the interesting property in that whenever a nan is used as an operand in a computation, the result is a nan. Therefore, @@ -506,15 +566,15 @@ --> + |
+
Home
| Search
| D
+| Comments
|
+
+ +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Floating Point@@ -100,20 +161,16 @@ Imaginary literals have an i suffix: -
+ There is no particular complex literal syntax, just add a real and imaginary type: -
+ Complex numbers have two properties: @@ -182,15 +239,15 @@ !<> F F T T no unordered or equal to + |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Functions@@ -66,9 +127,7 @@ derived class, unless they are also private. For example: -
+ Covariant return types are supported, which means that the overriding function in a derived class can return a type that is derived from the type returned by the overridden function: -
+ Function Inheritance and OverridingA functions in a derived class with the same name and parameter types as a function in a base class overrides that function: -
+ However, when doing overload resolution, the functions in the base class are not considered: -
+ To consider the base class's functions in the overload resolution process, use an AliasDeclaration: -
+ A function parameter's default value is not inherited: -
+ Inline Functions@@ -283,11 +332,9 @@ in is the default; out and inout work like storage classes. For example: -
+ x is in, y is out, z is inout, and q is in. @@ -311,9 +358,7 @@ out parameters are set to the default initializer for the type of it. For example: -
+
+ There must have at least one non-variadic parameter declared. -
+ This kind of function matches the C calling convention for variadic functions, and is most useful for calling C library @@ -372,9 +413,7 @@ arguments. To access the arguments, _argptr must be cast to a pointer to the expected argument type: -
+ To protect against the vagaries of stack layouts on different CPU architectures, use std.c.stdarg to access the variadic arguments: -
+ Variadic Functions With Type Info@@ -401,12 +438,10 @@ It has D linkage, and need not have any non-variadic parameters declared: -
+ These variadic functions have a special local variable declared for them, @@ -415,9 +450,7 @@ arguments. To access the arguments, _argptr must be cast to a pointer to the expected argument type: -
+ An additional hidden argument with the name _arguments and type TypeInfo[] @@ -433,9 +466,7 @@ _arguments gives the number of arguments and the type of each, enabling the creation of typesafe variadic functions. -
+ which prints: -
+ To protect against the vagaries of stack layouts on different CPU architectures, use std.stdarg to access the variadic arguments: -
+ Typesafe Variadic Functions@@ -549,9 +576,7 @@ For arrays: -
+ For static arrays: -
+ For class objects: -
+ An implementation may construct the object or array instance on the stack. Therefore, it is an error to refer to that instance after the variadic function has returned: -
+ For other types, the argument is built with itself, as in: -
+ Local Variables@@ -670,9 +687,7 @@ It is an error to declare a local variable that hides another local variable in the same function: -
+ While this might look unreasonable, in practice whenever this is done it either is a @@ -700,9 +715,7 @@ Functions may be nested within other functions: -
+ Nested functions can only be accessed by the most nested lexically enclosing function, or by another nested function at the same nesting depth: -
+ Nested functions have access to the variables and other symbols defined by the lexically enclosing function. This access includes both the ability to read and write them. -
+ This access can span multiple nesting levels: -
+ Static nested functions cannot access any stack variables of any lexically enclosing function, but can access static variables. This is analogous to how static member functions behave. -
+ Functions can be nested within member functions: -
+ Member functions of nested classes and structs do not have access to the stack variables of the enclosing function, but do have access to the other symbols: -
+ Nested functions always have the D function linkage type. @@ -866,21 +867,17 @@ scope are processed in order. This means that two nested functions cannot mutually call each other: -
+ The solution is to use a delegate: -
+ Future directions: This restriction may be removed. @@ -897,9 +894,7 @@ A function pointer can point to a static nested function: -
+ A delegate can be set to a non-static nested function: -
+ The stack variables, however, are not valid once the function declaring them has exited, in the same manner that pointers to stack variables are not valid upon exit from a function: -
+ Delegates to non-static nested functions contain two pieces of data: the pointer to the stack frame of the lexically enclosing @@ -956,9 +947,7 @@ Both forms of delegates are interchangeable, and are actually the same type: -
+ This combining of the environment and the function is called a dynamic closure. @@ -992,15 +981,15 @@ See Function Literals. + |
+
Home
| Search
| D
+| Comments
|
+
+ + + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
Future Directions@@ -52,15 +122,15 @@ |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Garbage Collection@@ -201,31 +262,25 @@
+ The garbage collector does not scan non-pointer types for roots.
+
+ A compacting garbage collector may change this value. @@ -243,11 +298,9 @@
+ ... since, again, the garbage collector can move objects around in memory. @@ -255,24 +308,20 @@
+
+ } Misaligned pointers may be used if the underlying hardware supports them and the pointer is never used to point into the gc heap. @@ -295,25 +344,21 @@
|
+
+
+Home
+| Search
+| D
+| Comments
+
+|
+
+ + + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
+
+
+Glossary+ +
|
Add feedback and comments regarding this + page.
+ +
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Embedding D in HTML@@ -76,9 +137,7 @@ Here's an example of the D program "hello world" embedded in this very HTML file. This file can be compiled and run. -
+ + |
+
Home
| Search
| D
+| Comments
|
+
+ + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
Converting C .h Files to D Modules@@ -77,14 +147,12 @@ Generally, surround the entire module with: -
+ to give it C linkage. @@ -152,130 +220,104 @@ as D will implicitly convert strings to wide characters if necessary. However, one can also replace: -
+ with: -
+ MacrosLists of macros like: -
+ can be replaced with: -
+ or with: -
+ Function style macros, such as: -
+ can be replaced with functions: -
+ Declaration ListsD doesn't allow declaration lists to change the type. Hence: -
+ should be written as: -
+ Void Parameter ListsFunctions that take no parameters: -
+ are in D: -
+ Const Type ModifiersD has const as a storage class, not a type modifier. Hence, just drop any const used as a type modifier: -
+ becomes: -
+ Extern Global C Variables@@ -286,29 +328,23 @@ in that module. For example, given a C header file named foo.h: -
+ It can be replaced with two D modules, foo.d: -
+ and fooextern.d: -
+ The foo.obj file is linked in, and fooextern.obj is not. While this is not the most elegant looking method, it does @@ -319,44 +355,36 @@ alias is the D equivalent to the C typedef: -
+ becomes: -
+ StructsReplace declarations like: -
+ with: -
+ Struct Member Alignment@@ -365,9 +393,7 @@ if the .h file has some #pragma's to control alignment, they can be duplicated with the D align attribute: -
+ becomes: -
+ Nested Structs-
+ becomes: -
+ __cdecl, __pascal, __stdcall-
+ becomes: -
+ __declspec(dllimport)-
+ becomes: -
+ __fastcallUnfortunately, D doesn't support the __fastcall convention. Therefore, a shim will be needed, either written in C: -
+ and compiled with a C compiler that supports __fastcall and linked in, or compile the above, disassemble it with @@ -499,15 +509,15 @@ and insert it in a D myfoo shim with inline assembler. + |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
D x86 Inline Assembler@@ -1097,15 +1158,15 @@ |
+
|
+
+ + + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
+
+ D Programming Language+ +"It seems to me that most of the "new" programming languages + fall into one of two categories: Those from academia with radical + new paradigms and those from large corporations with a focus on RAD + and the web. Maybe it's time for a new language born out of + practical experience implementing compilers." -- Michael+ + "Great, just what I need.. another D in programming." -- Segfault+ + This is the reference document for the D programming language. + D was conceived in December 1999 by Walter Bright as a reengineering of C and C++, + and has grown and evolved with helpful + suggestions and critiques by friends and colleagues. + + +Check out the quick comparison + of D with C, C++, C# and Java. + +The D newsgroup in + news.digitalmars.com + server is where discussions + of this should go. Suggestions, criticism, kudos, flames, etc., + are all welcome there. + Alternatively, try the + D forum. + There also may be a local D user group + in your community (or you can start one!). + + +Download the current version + of the compiler for Win32 and x86 Linux and try it out. + +David Friedman has integrated the + D frontend with GCC. + + Alternate versions of this document: + +
Walter's SDWest 2004 + + presentation on D. + +Do you feel the + need for speed? + +Note: all D users agree that by downloading and using + D, or reading the D specs, + they will explicitly identify any claims to intellectual property + rights with a copyright or patent notice in any posted or emailed + feedback sent to Digital Mars. + + |
Add feedback and comments regarding this + page.
+ +
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Interfaces-
+ Interfaces describe a list of functions that a class that inherits from the interface must implement. @@ -67,9 +126,7 @@ Interfaces cannot derive from classes; only from other interfaces. Classes cannot derive from an interface multiple times. -
+ An instance of an interface cannot be created. -
+ Interface member functions do not have implementations. -
+ All interface functions must be defined in a class that inherits from that interface: -
+ Interfaces can be inherited and functions overridden: -
+ Interfaces can be reimplemented in derived classes: -
+ A reimplemented interface must implement all the interface functions, it does not inherit them from a super class: -
+ COM Interfaces@@ -230,15 +275,15 @@ for that interface in standard COM fashion. + |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Interfacing to C@@ -63,23 +124,19 @@ The C function must be declared and given a calling convention, most likely the "C" calling convention, for example: -
+ and then it can be called within D code in the obvious way: -
+ There are several things going on here: @@ -107,9 +164,7 @@ use an attribute that is compatible with the C compiler, most likely the extern (C): -
+ Storage Allocation@@ -358,14 +413,12 @@ dynamic arrays are a length followed by a pointer to the data, the %.*s format works perfectly: -
+ The printf format string literal in the example doesn't end with \0. This is because string literals, @@ -400,15 +453,15 @@ D class objects are incompatible with C++ class objects. + |
+
|
+
+ + + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
+
D Programming Language"It seems to me that most of the "new" programming languages @@ -91,28 +174,31 @@ rights with a copyright or patent notice in any posted or emailed feedback sent to Digital Mars. + |
Add feedback and comments regarding this page.
-
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Lexical@@ -161,37 +222,31 @@End of File-
+ The source text is terminated by whichever comes first. End of Line-
+ There is no backslash line splicing, nor are there any limits on the length of a line. White Space-
+ White space is defined as a sequence of one or more of spaces, tabs, vertical tabs, form feeds, end of lines, or comments. Comments-
+ D has three kinds of comments:
Tokens-
+ Identifiers-
+ Identifiers start with a letter, _, or universal alpha, @@ -349,9 +398,7 @@ String Literals-
+ A string literal is either a double quoted string, a wysiwyg quoted string, an escape sequence, or a hex string. @@ -486,7 +533,8 @@ juxtaposition: - "hello " ~ "world" ~ \n // forms the string 'h','e','l','l','o',' ','w','o','r','l','d',linefeed + "hello " ~ "world" ~ \n // forms the string 'h','e','l','l','o',' ', + // 'w','o','r','l','d',linefeedThe following are all equivalent: @@ -523,25 +571,21 @@ Character Literals-
+ Character literals are a single character or escape sequence enclosed by single quotes, ' '. Integer Literals-
+ Integers can be specified in decimal, binary, octal, or hexadecimal. @@ -687,9 +731,7 @@ Floating Literals-
+ Floats can be in decimal or hexadecimal format, as in standard C. @@ -770,9 +812,7 @@ Keywords are reserved identifiers. -
+ Special Tokens@@ -924,16 +964,14 @@ There is currently only one special token sequence, #line. -
+ This sets the source line number to Integer, and optionally the source file name to Filespec, @@ -945,25 +983,23 @@ For example: -
+ Note that the backslash character is not treated specially inside Filespec strings. + |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Memory Management@@ -84,9 +145,7 @@ For example, a function to convert an array of characters to upper case: -
+ Note that the caller's version of s[] is also modified. This may be not at all what was intended, or worse, s[] may be a slice @@ -119,9 +178,7 @@ it'll have to be done explicitly in the code. Here's toupper() rewritten to implement copy-on-write in an efficient manner: -
+ Copy-on-write is the protocol implemented by array processing functions in the D Phobos runtime library. @@ -193,9 +250,7 @@ deallocating an object when done with it, put it on a free list. When allocating, pull one off the free list first. -
+ Such free list approaches can be very high performance. @@ -272,9 +327,7 @@ For example, to allocate using the C runtime library's malloc and free: -
+ The critical features of new() are: @@ -366,9 +419,7 @@ 'marked', and then whole sections of memory are released simply by resetting the stack pointer back to a marked point. -
+
+
|
+
Home
| Search
| D
+| Comments
|
+
+ +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Mixins@@ -75,9 +136,7 @@ templated nested functions, which is not possible with template instantiations. -
+ Mixins can be parameterized: -
+ Mixins can add virtual functions to a class: -
+ Mixins are evaluted in the scope of where they appear, not the scope of the template declaration: -
+ Mixins can parameterize symbols using alias parameters: -
+ This example uses a mixin to implement a generic Duff's device for an arbitrary statement (in this case, the arbitrary statement is in bold). A nested function is generated as well as a delegate literal, these can be inlined by the compiler: -
+ Mixin Scope@@ -242,9 +291,7 @@ as a declaration in the surrounding scope, the surrounding declaration overrides the mixin one: -
+ If two different mixins are put in the same scope, and each define a declaration with the same name, there is an ambiguity error when the declaration is referenced: -
+ If a mixin has a MixinIdentifier, it can be used to disambiguate: -
+ A mixin has its own scope, even if a declaration is overridden by the enclosing one: -
+ + |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Modules-
+ Modules have a one-to-one correspondence with source files. @@ -97,7 +156,7 @@ by surrounding attributes or other modifiers. - Modules can be grouped together in heirarchies called packages. + Modules can be grouped together in hierarchies called packages. Module Declaration@@ -105,16 +164,14 @@ package it belongs to. If absent, the module name is taken to be the same name (stripped of path and extension) of the source file name. -
+ The Identifier preceding the rightmost are the packages that the module is in. The packages correspond to directory names in @@ -127,11 +184,9 @@ Example: -
+ By convention, package and module names are all lower case. This is because those names have a one-to-one correspondence with the operating @@ -144,16 +199,14 @@ Rather than text include files, D imports symbols symbolically with the import declaration: -
+ The rightmost Identifier becomes the module name. The top level scope in the module is merged with the current scope. @@ -161,12 +214,10 @@ Example: -
+ Scope and Modules@@ -179,9 +230,7 @@ For example, assume the following modules: -
+ then: -
+ and: -
+ and: -
+ and: -
+ If the import is private, such as: -
+ then def is not searched when another module imports abc. @@ -248,9 +287,7 @@ to access a name hidden by a local name. This is done with the global scope operator, which is a leading '.': -
+ The leading '.' means look up the name at the module scope level. @@ -304,15 +341,15 @@ Unit tests are run in the lexical order in which they appear within a module. + |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Operator Overloading@@ -591,15 +652,15 @@ be overloadable. The names of the overloaded operators may change. + |
+
Home
| Search
| D
+| Comments
|
+
+ + + · Overview + · D for Win32 + · Win32 DLLs in D + · C .h to D Modules + · FAQ + · Style Guide + · Example: wc + · Future + · D Change Log + · Tech Tips + · Glossary + · Acknowledgements + + Tools + + · DMD D Compiler + · GDC D Compiler + · Linker + · Profiler + + Community + + · News Digest + · News + · Forum + · Announcements + · Learn + · D links + + Archives + + · digitalmars.D + · digitalmars.D.dtl + · digitalmars.D.announce + · digitalmars.D.learn + · digitalmars.D.bugs + · D.gnu + · Old D + + + |
+
+
Overview@@ -477,7 +547,7 @@
class Foo
{
- int foo(Bar *c) { return c->bar; }
+ int foo(Bar *c) { return c->bar(); }
};
class Bar
@@ -903,9 +973,7 @@
+ + |
+
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+object+ +This module is implicitly imported. + +
|
+ + + + + +
+ + + + diff -uNr dmd-0.129/dmd/html/d/phobos/phobos.html dmd-0.130/dmd/html/d/phobos/phobos.html --- dmd-0.129/dmd/html/d/phobos/phobos.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/phobos.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,429 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+PhobosD Runtime LibraryPhilosophy+ + Each module in Phobos conforms as much as possible to the + following design goals. These are goals + rather than requirements because D is not a religion, + it's a programming language, and it recognizes that + sometimes the goals are contradictory and counterproductive + in certain situations, and programmers have + jobs that need to get done. + +
+ Imports+ + Runtime library modules can be imported with the + import statement. Each module falls into one of several + packages: + +
+ std: Core library modules+ +
+ std.windows: Modules specific to the Windows operating system+ +
+ std.linux: Modules specific to the Linux operating system+ ++ std.c: Interface to C functions+ +
+ std.c.windows: Interface to C Windows functions+ +
+ std.c.linux: Interface to C Linux functions+ +
+ std.c.stdio+ +
|
+ + + + + +
+ + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_base64.html dmd-0.130/dmd/html/d/phobos/std_base64.html --- dmd-0.129/dmd/html/d/phobos/std_base64.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_base64.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.base64+ + +Encodes/decodes base64 data. + + + |
+ + + + + +
+ + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_boxer.html dmd-0.130/dmd/html/d/phobos/std_boxer.html --- dmd-0.129/dmd/html/d/phobos/std_boxer.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_boxer.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,327 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+
+
+std.boxer+ + This module is a set of types and functions for converting any object + (value or heap) into a generic box type, allowing the user to pass that + object around without knowing what's in the box, and then allowing him + to recover the value afterwards. ++ + Example + +
+ + + That is the basic interface and will usually be all that you need to + understand. If it cannot unbox the object to the given type, it throws + UnboxException. As demonstrated, it uses implicit casts to behave in the + exact same way that static types behave. So for example, you can unbox + from int to real, but you cannot unbox from real to int: that would + require an explicit cast. + + + This therefore means that attempting to unbox an int as a string will + throw an error instead of formatting it. In general, you can call the + toString method on the box and receive a good result, depending upon + whether std.string.format accepts it. + + + Boxes can be compared to one another and they can be used as keys for + associative arrays. + + + There are also functions for converting to and from arrays of boxes. + + + Example +
+ + One use of this is to support a variadic function more easily and + robustly; simply call "boxArray(_arguments, _argptr)", then + do whatever you need to do with the array. + +
|
+ + + + + +
+ + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_compiler.html dmd-0.130/dmd/html/d/phobos/std_compiler.html --- dmd-0.129/dmd/html/d/phobos/std_compiler.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_compiler.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.compiler+ + +
|
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_conv.html dmd-0.130/dmd/html/d/phobos/std_conv.html --- dmd-0.129/dmd/html/d/phobos/std_conv.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_conv.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.conv+ + std.conv provides basic building blocks for conversions from + strings to integral types. They differ from the C functions atoi() + and atol() by not allowing whitespace or overflows. ++ + For conversion to signed types, the grammar recognized is: + + + Integer: + Sign UnsignedInteger + UnsignedInteger + + Sign: + + + - ++ + For conversion to unsigned types, the grammar recognized is: + + + UnsignedInteger: + DecimalDigit + DecimalDigit UnsignedInteger ++ + Any deviation from that grammar causes a ConvError exception + to be thrown. Any overflows cause a ConvOverflowError to + be thrown. +
|
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_cstream.html dmd-0.130/dmd/html/d/phobos/std_cstream.html --- dmd-0.129/dmd/html/d/phobos/std_cstream.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_cstream.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.cstream+ + + +The std.cstream module bridges std.c.stdio (or std.stdio) and std.stream. Both std.c.stdio and std.stream are publically imported by std.cstream. + +
|
+ + + + + +
+ + + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_ctype.html dmd-0.130/dmd/html/d/phobos/std_ctype.html --- dmd-0.129/dmd/html/d/phobos/std_ctype.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_ctype.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,221 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.ctype+ + +
|
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_date.html dmd-0.130/dmd/html/d/phobos/std_date.html --- dmd-0.129/dmd/html/d/phobos/std_date.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_date.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.date+ + Dates are represented in several formats. The date implementation + revolves around a central type, d_time, from which other + formats are converted to and from. ++ +
|
+ + + + + +
+ + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_file.html dmd-0.130/dmd/html/d/phobos/std_file.html --- dmd-0.129/dmd/html/d/phobos/std_file.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_file.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.file+ +
|
+ + + + + +
+ + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_format.html dmd-0.130/dmd/html/d/phobos/std_format.html --- dmd-0.129/dmd/html/d/phobos/std_format.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_format.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,446 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.format+ + + +This module implements the workhorse functionality for string and I/O +formatting. It's comparable to C99's vsprintf(). + +
Format String+ + Format strings consist of characters interspersed with + format specifications. Characters are simply copied + to the output (such as putc) after any necessary conversion + to the corresponding UTF-8 sequence. ++ + A format specification starts with a '%' character, + and has the following grammar: + + + FormatSpecification: + '%%' + '%' Flags Width Precision FormatChar + + Flags: + empty + '-' Flags + '+' Flags + '#' Flags + '0' Flags + ' ' Flags + + Width: + empty + Integer + '*' + + Precision: + empty + '.' + '.' Integer + '.*' + + Integer: + Digit + Digit Integer + + Digit: + '0' + '1' + '2' + '3' + '4' + '5' + '6' + '7' + '8' + '9' + + FormatChar: + 's' + 'b' + 'd' + 'o' + 'x' + 'X' + 'e' + 'E' + 'f' + 'F' + 'g' + 'G' + 'a' + 'A' ++ +
+ + Example+ +
+ import std.c.stdio;
+ import std.format;
+
+ void formattedPrint(...)
+ {
+ void putc(char c)
+ {
+ fputc(c, stdout);
+ }
+
+ std.format.doFormat(&putc, _arguments, _argptr);
+ }
+
+ ...
+
+ int x = 27;
+ formattedPrint("The answer is %s:", x, 6); // prints 'The answer is 27:6'
+
+
+
+ |
+ + + + + +
+ + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_gc.html dmd-0.130/dmd/html/d/phobos/std_gc.html --- dmd-0.129/dmd/html/d/phobos/std_gc.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_gc.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.gc+ + + The garbage collector normally works behind the scenes without + needing any specific interaction. These functions are for + advanced applications that benefit from tuning the operation of the + collector. + +
|
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_intrinsic.html dmd-0.130/dmd/html/d/phobos/std_intrinsic.html --- dmd-0.129/dmd/html/d/phobos/std_intrinsic.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_intrinsic.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,307 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.intrinsic+ + + Intrinsic functions are functions built in to the compiler, + usually to take advantage of specific CPU features that + are inefficient to handle via external functions. + The compiler's optimizer and code generator are fully + integrated in with intrinsic functions, bringing to bear + their full power on them. + This can result in some surprising speedups. + +
|
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_math.html dmd-0.130/dmd/html/d/phobos/std_math.html --- dmd-0.129/dmd/html/d/phobos/std_math.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_math.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,472 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.math+ +
|
+ + + + + +
+ + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_md5.html dmd-0.130/dmd/html/d/phobos/std_md5.html --- dmd-0.129/dmd/html/d/phobos/std_md5.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_md5.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.md5+ + +Computes MD5 digests of arbitrary data. MD5 digests are 16 byte quantities +that are like a checksum or crc, but are more robust. ++There are two ways to do this. The first does it all in one function call +to sum(). The second is for when the data is buffered. + +The routines and algorithms are derived from the +RSA Data Security, Inc. MD5 Message-Digest Algorithm. + + +
Example+ +
+ + + + |
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_mmfile.html dmd-0.130/dmd/html/d/phobos/std_mmfile.html --- dmd-0.129/dmd/html/d/phobos/std_mmfile.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_mmfile.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.mmfile+ + + +Read and write memory mapped files. + +
Notes+ +
|
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_openrj.html dmd-0.130/dmd/html/d/phobos/std_openrj.html --- dmd-0.129/dmd/html/d/phobos/std_openrj.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_openrj.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,585 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.openrj+ + + +Open-RJ is an open-source library that implements readers of the Record-Jar +structured text file format, designed and implemented by Matthew Wilson, as an +exemplar project for his column Positive Integration in +C/C++ Users Journal. ++It is implemented in C & C++, with a C-API. +The implementation of the basic library is platform-independent. Mappings are +provided to several languages (including C++, +D, +Ruby +and +STL), +and others (COM, Java, .NET, Perl, Python) are planned. In addition to +platform-independence, the library focuses on small runtime +costs - memory and speed - and the classic UNIX attributes of +discoverability and visibility. + + +What is the Record-Jar format?++As described in the excellent book +"The Art Of UNIX Programming", a Record-Jar structured format file +consists of records and fields. + ++A field is a single line - optionally extended with trailing '\' - that contains +a name, separated from an optional value by ':'. + ++A record is a list of fields, whose contents are arbitrary and can vary between +records in the same database. Records are separated by a line that begins with +"%%". The record separator also acts as a comment, so +anything can come on a record separator line after the first two characters. + ++A database is a correctly parsed Record-Jar file. The Open-RJ API (and language +mappings) provide access to all the records in the database and the complete set +of fields. Hence, you may work with fields on a per-record basis, or treat the database +as a single record and with all fields in the database. + ++A very simple Record-Jar file, representing a Pets Database, is shown below: + + ++Name: Elsa +Species: Dog +Breed: Mixed +%% +Name: Fluffy Kitten +Species: Cat +%% +Name: Rebel +Species: Dog +Breed: German + Shepherd +%% +Name: Pepper +Species: Dog +Breed: Border Collie +%% +Name: Samson +Species: Dog +Breed: Ridgeback +%% +Name: Sheltie +Species: Dog +Breed: Shetland + Sheepdog +%% +Name: Sparky +Species: Cat +%% ++ + +And that's pretty much all there is to it. There are no restrictions on what fields may +be in a record, and no controls over whether all records have the same fields or not. +That's the job of higher layers of application functionality. We keep Record-Jar simple +so it's reliable, portable and fast, and it's those things in spades! + + +std.openrj++The D mapping of Open-RJ is packaged with Phobos in the std.openrj +module. It consists of four classes: +
+
+
+
+ + + + + + +
+ + + + + + + + + + + + + +
+
+
+
+ + + + + + + + + + + + + + + + + +
+
+
+
+ + + + + +
+
+
+
+
+
+ + The DatabaseException class has the following properties: + methods: +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ + Copyright (c) 2004-2005 by Matthew Wilson, Synesis Software Pty Ltd, All Rights Reserved + + |
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_outbuffer.html dmd-0.130/dmd/html/d/phobos/std_outbuffer.html --- dmd-0.129/dmd/html/d/phobos/std_outbuffer.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_outbuffer.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,239 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.outbuffer+ + + +
|
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_path.html dmd-0.130/dmd/html/d/phobos/std_path.html --- dmd-0.129/dmd/html/d/phobos/std_path.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_path.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.path+ +
|
+ + + + + +
+ + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_process.html dmd-0.130/dmd/html/d/phobos/std_process.html --- dmd-0.129/dmd/html/d/phobos/std_process.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_process.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,177 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.process+ + + +
|
+ + + + + +
+ + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_random.html dmd-0.130/dmd/html/d/phobos/std_random.html --- dmd-0.129/dmd/html/d/phobos/std_random.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_random.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.random+ + +
|
+ + + + + +
+ + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_recls.html dmd-0.130/dmd/html/d/phobos/std_recls.html --- dmd-0.129/dmd/html/d/phobos/std_recls.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_recls.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,470 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.recls+ + + ++recls - standing for recursive ls - is a platform-independent +recursive search library, designed and implemented by Matthew Wilson, as the first +exemplar project for his column Positive Integration in +C/C++ Users Journal. + +recls currently supports recursive searching of file systems (UNIX and Windows), and +FTP sites (currently Windows-only). Future enhancements may include recursive-searching of the +Windows registry, source-code control systems, and, of course, FTP-searching for UNIX platforms. + +recls is implemented in C++, using the +STLSoft +libraries (which are also bundled with Digital Mars; see +stlsoft.digitalmars.com), +and presents a C-API. recls is also mapped to a host of other languages and +technologies, including C++, COM, C#/.NET, Java, Ruby +and STL among an ever-expanding list. Given its non-trivial size, the recls D +mapping is a good place to learn about interfacing C libraries to D. + +The recls homepage is www.recls.org, +from which updates to the library, and all the other language mappings, may be obtained. Support +for recls has evolved to piggy-back on the +STLSoft newsgroup, although +questions about using recls in D should be directed through the main +D newsgroup, and bugs in +recls (in D) should be reported to the +D bugs newsgroup. + +The Windows version of the D mapping of recls uses a crude-but-adequate delay-loading +mechanism such that linking to WinInet.lib is not required. This strategy was necessitated by +D's linkage model, and was elected to avoid encumbering executables with something that they +may not use. There is are negative effects if the program explicitly uses WinInet.lib for +other aspects. + +The recls object model is comprised of the following classes: +
+The basic usage is as follows: +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+ + Copyright (c) 2003-2004 by Matthew Wilson, Synesis Software Pty Ltd, All Rights Reserved + + |
+ + + + + +
+ + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_regexp.html dmd-0.130/dmd/html/d/phobos/std_regexp.html --- dmd-0.129/dmd/html/d/phobos/std_regexp.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_regexp.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,408 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.regexp+ + +Regular expressions +are a powerful method of string pattern matching. +The regular expression +language used is the same as that commonly used, however, some of the very +advanced forms may behave slightly differently. ++ +
attributes+ + attributes are a string controlling the interpretation + of the regulat expression. It consists of a sequence of one or more + of the following characters: ++ +
format+ + format strings are a sequence of characters with embedded + format commands used to generate a new string from a regular + expression match. + The format commands are: ++ +
|
+ + + + + +
+ + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_socket.html dmd-0.130/dmd/html/d/phobos/std_socket.html --- dmd-0.129/dmd/html/d/phobos/std_socket.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_socket.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,687 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.socket+ + + +
Notes+ + For Win32 systems, link with ws2_32.lib. + +Example+ + See /dmd/samples/d/listener.d. + +written by Christopher E. Miller + + + |
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_socketstream.html dmd-0.130/dmd/html/d/phobos/std_socketstream.html --- dmd-0.129/dmd/html/d/phobos/std_socketstream.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_socketstream.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.socketstream+ + +
Notes+ + For Win32 systems, link with ws2_32.lib. + +Example+ + See /dmd/samples/d/htmlget.d. + + + |
+ + + + + +
+ + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_stdint.html dmd-0.130/dmd/html/d/phobos/std_stdint.html --- dmd-0.129/dmd/html/d/phobos/std_stdint.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_stdint.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,275 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.stdint+ + + + D constrains integral types to specific sizes. But efficiency + of different sizes varies from machine to machine, + pointer sizes vary, and the maximum integer size varies. + stdint offers a portable way of trading off size + vs efficiency, in a manner compatible with the stdint.h + definitions in C. ++ + The exact aliases are types of exactly the specified number of bits. + The at least aliases are at least the specified number of bits + large, and can be larger. + The fast aliases are the fastest integral type supported by the + processor that is at least as wide as the specified number of bits. + + + The aliases are: + + +
+ + The ptr aliases are integral types guaranteed to be large enough + to hold a pointer without losing bits: + + +
+ + The max aliases are the largest integral types: + + +
|
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_stdio.html dmd-0.130/dmd/html/d/phobos/std_stdio.html --- dmd-0.129/dmd/html/d/phobos/std_stdio.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_stdio.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.stdio+ + + Standard I/O functions that extend std.c.stdio. + std.c.stdio is automatically imported when importing + std.stdio. + +
|
+ + + + + +
+ + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_stream.html dmd-0.130/dmd/html/d/phobos/std_stream.html --- dmd-0.129/dmd/html/d/phobos/std_stream.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_stream.html 2005-09-06 11:34:28.000000000 +0200 @@ -0,0 +1,818 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.stream+ + + + +
|
+ + + + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_string.html dmd-0.130/dmd/html/d/phobos/std_string.html --- dmd-0.129/dmd/html/d/phobos/std_string.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_string.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,524 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.string+ + + +To copy or not to copy?+ + When a function takes a string as a parameter, and returns a string, + is that string the same as the input string, modified in place, or + is it a modified copy of the input string? The D array convention is + "copy-on-write". This means that if no modifications are done, the + original string (or slices of it) can be returned. If any modifications + are done, the returned string is a copy. ++ +
Patterns+ + A pattern is an array of characters much like a character + class in regular expressions. A sequence of characters + can be given, such as "abcde". The '-' can represent a range + of characters, as "a-e" represents the same pattern as "abcde". + "a-fA-F0-9" represents all the hex characters. + If the first character of a pattern is '^', then the pattern + is negated, i.e. "^0-9" means any character except a digit. + The following functions use patterns. ++ + Note: In the future, the pattern syntax may be improved + to be more like regular expression character classes. + +
|
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_system.html dmd-0.130/dmd/html/d/phobos/std_system.html --- dmd-0.129/dmd/html/d/phobos/std_system.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_system.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.system+ + +
|
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_thread.html dmd-0.130/dmd/html/d/phobos/std_thread.html --- dmd-0.129/dmd/html/d/phobos/std_thread.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_thread.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,303 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.thread+ + The thread module defines the class Thread. + Thread is the basis + for writing multithreaded applications. Each thread + has a unique instance of class Thread associated with it. + It is important to use the Thread class to create and manage + threads as the garbage collector needs to know about all the threads. ++ +
+ +
|
+ + + + + +
+ + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_uri.html dmd-0.130/dmd/html/d/phobos/std_uri.html --- dmd-0.129/dmd/html/d/phobos/std_uri.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_uri.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.uri+ + Encode and decode Uniform Resource Identifiers (URIs). + URIs are used in internet transfer protocols. + Valid URI characters consist of letters, digits, and + the characters ;/?:@&=+$,-_.!~*'(). Escape sequences + consist of '%' followed by two hex digits. + +
|
+ + + + + +
+ + + + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_utf.html dmd-0.130/dmd/html/d/phobos/std_utf.html --- dmd-0.129/dmd/html/d/phobos/std_utf.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_utf.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,231 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.utf+ + Encode and decode UTF-8, UTF-16 and UTF-32 strings. + For more information on UTF-8, see + http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8. ++ + Note: For Win32 systems, the C wchar_t type + is UTF-16 and corresponds to the D wchar type. + For linux systems, the C wchar_t type + is UTF-32 and corresponds to the D utf.dchar type. + + + UTF character support is restricted to (0 <= character <= 0x10FFFF). + +
|
+ + + + + +
+ + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_zip.html dmd-0.130/dmd/html/d/phobos/std_zip.html --- dmd-0.129/dmd/html/d/phobos/std_zip.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_zip.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,351 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.zip+ + Read/write data in the zip archive format. + Makes use of the zlib compression library. + +
|
+ + + + + +
+ + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/std_zlib.html dmd-0.130/dmd/html/d/phobos/std_zlib.html --- dmd-0.129/dmd/html/d/phobos/std_zlib.html 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/std_zlib.html 2005-08-22 22:42:58.000000000 +0200 @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+Home
+| Search
+| D
+| Comments
+
+|
+ + +object + + +std + std.base64 + std.boxer + std.compiler + std.conv + std.ctype + std.date + std.file + std.format + std.gc + std.intrinsic + std.math + std.md5 + std.mmfile + std.openrj + std.outbuffer + std.path + std.process + std.random + std.recls + std.regexp + std.socket + std.socketstream + std.stdint + std.stdio + std.cstream + std.stream + std.string + std.system + std.thread + std.uri + std.utf + std.zip + std.zlib + +std.windows + +std.linux + +std.c + std.c.stdio + +std.c.windows + +std.c.linux + + + |
+
+
+
+std.zlib+ + Compress / decompress data using the + zlib library. + +
|
+ + + + + +
+ + + + + diff -uNr dmd-0.129/dmd/html/d/phobos/style.css dmd-0.130/dmd/html/d/phobos/style.css --- dmd-0.129/dmd/html/d/phobos/style.css 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.130/dmd/html/d/phobos/style.css 2005-05-21 13:32:18.000000000 +0200 @@ -0,0 +1,86 @@ +body +{ + background: white; + color: black; + font-family: sans-serif; +} +h1 +{ + text-align: center; + text-decoration: underline; +} +blockquote +{ + font-size: smaller; + font-style: italic; + margin-left: 0; + margin-right: 0; +} +pre +{ + background: #e7e7e7; + color: #000066; + border: 2px solid #cccccc; + padding: 1ex; + width: 640px; +} + +body#toc +{ + background: #dddddd; + font-size: small; +} + +div#tocheading +{ + border-bottom: 2px solid gray; + font-size: larger; + font-weight: bold; + text-align: center; + margin-bottom: 1ex; + padding-bottom: 1ex; +} +div#tocheading b +{ + color: red; + font-size: 36pt; + font-family: serif; +} +body#toc ul +{ + border-bottom: 2px solid gray; + list-style-type: none; + margin-left: 0; + margin-top: 0; + padding-bottom: 1ex; + padding-left: 0; +} +div#toccopyright +{ + font-size: smaller; + margin-bottom: 1ex; + padding-top: 3px; +} + +div#heading +{ + border-bottom: 2px solid black; + padding-bottom: 1ex; +} +div#lastupdate +{ + font-size: smaller; + font-style: italic; +} +a#dlink +{ + color: red; + font-weight: bold; +} +div#copyright +{ + border-top: 2px solid black; + font-size: smaller; + margin-bottom: 2ex; + padding-top: 3px; +} \ Ingen nyrad vid filslut diff -uNr dmd-0.129/dmd/html/d/phobos.html dmd-0.130/dmd/html/d/phobos.html --- dmd-0.129/dmd/html/d/phobos.html 2005-08-06 21:59:06.000000000 +0200 +++ dmd-0.130/dmd/html/d/phobos.html 1970-01-01 01:00:00.000000000 +0100 @@ -1,2894 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - -
-
-Home
-| Search
-| D
-
-- -
- -
- -
- -
- -
- -
-
- -
- -
- -
- -
- -
- - For conversion to signed types, the grammar recognized is: - -
- Integer: - Sign UnsignedInteger - UnsignedInteger - - Sign: - + - - -- - For conversion to unsigned types, the grammar recognized is: - -
- UnsignedInteger: - DecimalDigit - DecimalDigit UnsignedInteger -- - Any deviation from that grammar causes a ConvError exception - to be thrown. Any overflows cause a ConvOverflowError to - be thrown. -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- - -
- -
- - The usual arithmetic operations can be performed on d_time, - such as adding, subtracting, etc. Elapsed time in Ticks can - be computed by subtracting a starting d_time from an ending - d_time. -
- - An invalid value for d_time is represented by d_time.init. -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- - -
- -
- -
- -
- -
- -
- - -
- -
- - -
- - -
- - Both return the bit number of the first set bit. - The return value is undefined if v is zero. -
-
- Example
-
-
-
- import std.intrinsic;
-
- int main()
- {
- uint v;
- int x;
-
- v = 0x21;
- x = bsf(v);
- printf("bsf(x%x) = %d\n", v, x);
- x = bsr(v);
- printf("bsr(x%x) = %d\n", v, x);
- return 0;
- }
- |
-
- Output
-
- bsf(x21) = 0 - bsr(x21) = 5 -- -
- - p is a non-NULL pointer to an array of uints. - index is a bit number, starting with bit 0 of p[0], - and progressing. It addresses bits like the expression: -
- p[index / (uint.size*8)] & (1 << (index & ((uint.size*8) - 1))) --
- - All return a non-zero value if the bit was set, and a zero - if it was clear. -
- - Example - -
-
- import std.intrinsic;
-
- int main()
- {
- uint array[2];
-
- array[0] = 2;
- array[1] = 0x100;
-
- printf("btc(array, 35) = %d\n", btc(array, 35));
- printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
-
- printf("btc(array, 35) = %d\n", btc(array, 35));
- printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
-
- printf("bts(array, 35) = %d\n", bts(array, 35));
- printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
-
- printf("btr(array, 35) = %d\n", btr(array, 35));
- printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
-
- printf("bt(array, 1) = %d\n", bt(array, 1));
- printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
-
- return 0;
- }
- |
- - Output -
- btc(array, 35) = 0 - array = [0]:x2, [1]:x108 - btc(array, 35) = -1 - array = [0]:x2, [1]:x100 - bts(array, 35) = 0 - array = [0]:x2, [1]:x108 - btr(array, 35) = -1 - array = [0]:x2, [1]:x100 - bt(array, 1) = -1 - array = [0]:x2, [1]:x100 --
- -
- -
- -
- -
- -
| x - | return value - | invalid? - |
|---|---|---|
| ±INFINITY - | NAN - | yes - |
- -
| x - | return value - | invalid? - |
|---|---|---|
| ±0.0 - | ±0.0 - | no - |
| ±INFINITY - | NAN - | yes - |
- -
| x - | return value - | invalid? - |
|---|---|---|
| ±0.0 - | ±0.0 - | no - |
| ±INFINITY - | NAN - | yes - |
- -
- -
| value | x | exp - |
|---|---|---|
| +-0.0 | +-0.0 | 0 - |
| +INFINITY | +INFINITY | int.max - |
| -INFINITY | -INFINITY | int.min - |
| +-NAN | +-NAN | int.min - |
- -
- -
| x | return value | divide by 0? | invalid? - |
|---|---|---|---|
| ±0.0 | -INFINITY | yes | no - |
| < 0.0 | NAN | no | yes - |
| +INFINITY | +INFINITY | no | no - |
- -
| x | return value | divide by 0? | invalid? - |
|---|---|---|---|
| ±0.0 | -INFINITY | yes | no - |
| < 0.0 | NAN | no | yes - |
| +INFINITY | +INFINITY | no | no - |
- -
- -
- -
| x - | return value - | invalid? - |
|---|---|---|
| -0.0 - | -0.0 - | no - |
| <0.0 - | NAN - | yes - |
| +INFINITY - | +INFINITY - | no - |
- -
- -
| x - | log1p(x) - | divide by 0? - | invalid? - |
|---|---|---|---|
| ±0.0 - | ±0.0 - | no - | no - |
| -1.0 - | -INFINITY - | yes - | no - |
| <-1.0 - | NAN - | no - | yes - |
| +INFINITY - | -INFINITY - | no - | no - |
- -
| x - | ex-1 - |
|---|---|
| ±0.0 - | ±0.0 - |
| +INFINITY - | +INFINITY - |
| -INFINITY - | -1.0 - |
- -
- -
- sqrt(x2 + y2)- Note that hypot(x,y), hypot(y,x) and - hypot(x,-y) are equivalent.
| x - | y - | return value - | invalid? - |
|---|---|---|---|
| x - | +-0.0 - | fabs(x) - | no - |
| +-INFINITY - | y - | +INFINITY - | no - |
| +-INFINITY - | NAN - | +INFINITY - | no - |
- -
- -
- -
- -
- -
- -
- -
- -
-There are two ways to do this. The first does it all in one function call -to sum(). The second is for when the data is buffered. -
-The routines and algorithms are derived from the -RSA Data Security, Inc. MD5 Message-Digest Algorithm. -
- -
- -
- -
- -
- -
- -
-
-// This code is derived from the
-// RSA Data Security, Inc. MD5 Message-Digest Algorithm.
-
-import std.md5;
-import std.string;
-import std.c.stdio;
-
-int main(char[][] args)
-{
- for (int i = 1; i < args.length; i++)
- MDFile(args[i]);
- return 0;
-}
-
-/* Digests a file and prints the result. */
-void MDFile(char[] filename)
-{
- FILE* file;
- MD5_CTX context;
- int len;
- ubyte [4 * 1024] buffer;
- ubyte digest[16];
-
- if ((file = fopen(std.string.toStringz(filename), "rb")) == null)
- printf("%.*s can't be opened\n", filename);
- else
- {
- context.start();
- while ((len = fread(buffer, 1, buffer.size, file)) != 0)
- context.update(buffer[0 .. len]);
- context.finish(digest);
- fclose(file);
-
- printf("MD5 (%.*s) = ", filename);
- printDigest(digest);
- printf("\n");
- }
-}
- |
- - -
-
- -
- -
- -
-
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- - -
- - -
- - -
- - -
- - -
- - -
- - -
- - -
- - -
- - -
- - -
- -
- - -
- -
- -
-
- -
- -
- -
- -
- -
- -
- -
-
- - The exact aliases are types of exactly the specified number of bits. - The at least aliases are at least the specified number of bits - large, and can be larger. - The fast aliases are the fastest integral type supported by the - processor that is at least as wide as the specified number of bits. -
- - The aliases are: -
- -
| Exact Alias - | Description - | At Least Alias - | Description - | Fast Alias - | Description - |
|---|---|---|---|---|---|
| int8_t - | exactly 8 bits signed - | int_least8_t - | at least 8 bits signed - | int_fast8_t - | fast 8 bits signed - |
| uint8_t - | exactly 8 bits unsigned - | uint_least8_t - | at least 8 bits unsigned - | uint_fast8_t - | fast 8 bits unsigned - - |
| int16_t - | exactly 16 bits signed - | int_least16_t - | at least 16 bits signed - | int_fast16_t - | fast 16 bits signed - |
| uint16_t - | exactly 16 bits unsigned - | uint_least16_t - | at least 16 bits unsigned - | uint_fast16_t - | fast 16 bits unsigned - - |
| int32_t - | exactly 32 bits signed - | int_least32_t - | at least 32 bits signed - | int_fast32_t - | fast 32 bits signed - |
| uint32_t - | exactly 32 bits unsigned - | uint_least32_t - | at least 32 bits unsigned - | uint_fast32_t - | fast 32 bits unsigned - - |
| int64_t - | exactly 64 bits signed - | int_least64_t - | at least 64 bits signed - | int_fast64_t - | fast 64 bits signed - |
| uint64_t - | exactly 64 bits unsigned - | uint_least64_t - | at least 64 bits unsigned - | uint_fast64_t - | fast 64 bits unsigned - |
- - The ptr aliases are integral types guaranteed to be large enough - to hold a pointer without losing bits: -
- -
| Alias - | Description - |
|---|---|
| intptr_t - | signed integral type large enough to hold a pointer - |
| uintptr_t - | unsigned integral type large enough to hold a pointer - |
- - The max aliases are the largest integral types: -
- -
| Alias - | Description - |
|---|---|
| intmax_t - | the largest signed integral type - |
| uintmax_t - | the largest unsigned integral type - |
- -
- -
- -
- -
-
-
- -
- -
- -
- -
- -
- -
- -
- -
- -
-
-
- -
- -
- -
- -
- -
- -
- -
- -
-
-
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
seek(0, SeekPos.Current) or
- seek(pos, SeekPos.Set) respectively.
- - -
- -
- -
- -
- -
- -
- -
-
- -
- -
- -
- -
- -
- -
-
- -
-
- -
-
- -
-
- -
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
| TS - | Description - |
|---|---|
| INITIAL - | The thread hasn't been started yet. - |
| RUNNING - | The thread is running or paused. - |
| TERMINATED - | The thread has ended. - |
- -
-
| PRIORITY - | Description - |
|---|---|
| INCREASE - | Increase thread priority - |
| DECREASE - | Decrease thread priority - |
| IDLE - | Assign thread low priority - |
| CRITICAL - | Assign thread high priority - |
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- - Note: For Win32 systems, the C wchar_t type - is UTF-16 and corresponds to the D wchar type. - For linux systems, the C wchar_t type - is UTF-32 and corresponds to the D utf.dchar type. -
- - UTF character support is restricted to (0 <= character <= 0x10FFFF). - -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- ZipArchive archive = new ZipArchive(data);
-foreach (ArchiveMember am; archive)
-{
- printf("member name is '%.*s'\n", am.name);
-} |
-
- -
-
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- - - - - - - - - - diff -uNr dmd-0.129/dmd/html/d/portability.html dmd-0.130/dmd/html/d/portability.html --- dmd-0.129/dmd/html/d/portability.html 2005-05-19 15:08:50.000000000 +0200 +++ dmd-0.130/dmd/html/d/portability.html 2005-08-26 11:54:10.000000000 +0200 @@ -12,9 +12,15 @@ - - + + + + + + + + +
- +
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Portability Guide@@ -129,15 +190,15 @@ specific import, and then using that constant in an if statement. + |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Pragmas-
+ Pragmas are a way to pass special information to the compiler @@ -58,9 +117,7 @@ they can influence a statement, a block of statements, a declaration, or a block of declarations. -
+ The kind of pragma it is is determined by the Identifier. ExpressionList is a comma-separated list of @@ -98,19 +155,15 @@
+ + pragma(msg, "compiling...");
+ + pragma(lib, "foo.lib");@@ -121,34 +174,30 @@ are prefixed by the vendor's trademarked name, in a similar manner to version identifiers: -
+ Compilers must diagnose an error for unrecognized Pragmas, even if they are vendor specific ones. This implies that vendor specific pragmas should be wrapped in version statements: -
+ + |
+
Home
| Search
| D
+| Comments
|
+
+ +D vs C/C++/C#/Java +Rationale for Builtins +Converting C to D +Converting C++ to D +The C Preprocessor vs D +D strings vs C++ std::string +D complex vs C++ std::complex +D Contract Programming vs C++ + + |
+
+
The C Preprocessor Versus D@@ -79,21 +117,17 @@ fragile syntax for precompiled headers are simply unnecessary and irrelevant to D. -
+ The D WayD uses symbolic imports: -
+ #pragma once@@ -103,22 +137,18 @@ C header files frequently need to be protected against being #include'd multiple times. To do it, a header file will contain the line: -
+ or the more portable: -
+ The D Way@@ -142,15 +172,13 @@ that get mapped onto externally defined data structures, there is a need, and it is handled with: -
+ Macros@@ -189,53 +217,43 @@The C Preprocessor Way-
+ The D Way-
+ The C Preprocessor Way-
+ The D Way-
+ The C Preprocessor Way-
+ The D Way-
+ D's optimizer will inline the function, and will do the conversion of the @@ -265,16 +281,14 @@ The C Preprocessor Way-
+ The D Way@@ -285,41 +299,33 @@The C Preprocessor Way-
+ The D Way-
+ The C Preprocessor Way-
+ In declarations.h: -
+ The D Way@@ -332,19 +338,15 @@The C Preprocessor Way-
+ The D Way-
+ The compiler optimizer will inline it; no efficiency is lost. @@ -352,11 +354,9 @@ The C Preprocessor Way-
+ The D Way@@ -368,9 +368,7 @@The C Preprocessor Way-
+ The D WayCalling conventions can be specified in blocks, so there's no need to change it for every function: -
+ The C Preprocessor Way-
+ The D Way@@ -418,9 +412,7 @@ Selecting which function to use based on text substitution: -
+ The D WayD enables declarations of symbols that are aliases of other symbols: -
+ @@ -508,9 +498,7 @@ function, so it is implemented as a macro. For example, consider this fragment from a byte code interpreter: -
+ This suffers from numerous problems:
+ The problems addressed are:
+ This has the limitations inherent in preprocessor expressions (i.e. integer constant expressions only, no casts, no sizeof, @@ -622,23 +606,19 @@ These problems can be circumvented to some extent by defining a static_assert macro (thanks to M. Wilson): -
+ and using it like: -
+ This works by causing a compile time semantic error if the condition evaluates @@ -652,9 +632,7 @@ which can be used anywhere a declaration or a statement can be used. For example: -
+ Mixins@@ -728,15 +706,15 @@ |
+
Home
| Search
| D
+| Comments
|
+
+ + +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Properties@@ -91,9 +152,7 @@ default initializer for that variable or field. For example: -
+
+ To use it: -
+ The absence of a read method means that the property is write-only. The absence of a write method means that the property is read-only. @@ -170,15 +225,15 @@ Note: Properties currently cannot be the lvalue of an op=, ++, or -- operator. + |
+
Home
| Search
| D
+| Comments
-
+ |
+ The second overload does the reverse overload, but it cannot be virtual, and so has a confusing asymmetry with @@ -85,25 +91,21 @@ when the operands are objects of different types: -
-
+ |
+ Should add() be in class A or B? The obvious stylistic solution would be to put it in the class of the first operand, -
-
+ |
+
- +(op1 < op2) - |
+ does not yield the same result as: -
- +!(op1 >= op2) - |
+ if the NaNs are done correctly.
- +static if (...) int x; else long x; x = 3; - |
+ whereas: -
- +if (...) int x; else long x; x = 3; // error, x is not defined - |
+
-
+ |
+
-
+ |
+
- +static if (0 || is(int T)) T x; - |
+
+
Home
| Search
| D
+| Comments
|
+
+ +· Lexical +· Modules +· Declarations +· Types +· Properties +· Attributes +· Pragmas +· Expressions +· Statements +· Arrays +· Structs & Unions +· Classes +· Interfaces +· Enums +· Functions +· Operator Overloading +· Templates +· Mixins +· Contracts +· Conditional Compilation +· Handling errors +· Garbage Collection +· Memory Management +· Floating Point +· Inline Assembler +· Interfacing To C +· Portability Guide +· Embedding D in HTML +· Named Character Entities +· Application Binary Interface + + |
+
+
Statements@@ -46,9 +107,7 @@ C and C++ programmers will find the D statements very familiar, with a few interesting additions. -
+
+ Any statement can be labelled, including empty statements, and so can serve as the target @@ -108,9 +165,7 @@ A block statement is a sequence of statements enclosed by { }. The statements are executed in lexical order. -
+ A block statement introduces a new scope for local symbols. A local symbol's name, however, must be unique within the function. -
+ The idea is to avoid bugs in complex functions caused by scoped declarations inadvertantly hiding previous ones. @@ -164,12 +217,10 @@ The expression is evaluated. -
+ Expressions that have no effect, like (x + x), are illegal in expression statements. @@ -178,9 +229,7 @@ Declaration statements declare and initialize variables. -
+ If no Initializer is there to initialize the variable, it is initialized to the default value for its type. @@ -200,13 +249,11 @@ If statements provide simple conditional execution of statements. -
+ Expression is evaluated and must have a type that can be converted to a boolean. If it's true the if @@ -221,12 +268,10 @@ While statements implement simple loops. -
+ Expression is evaluated and must have a type that can be converted to a boolean. If it's true the @@ -243,12 +288,10 @@ Do-While statements implement simple loops. -
+ Statement is executed. Then Expression is evaluated and must have a type that @@ -266,9 +309,7 @@ For statements implement loops with initialization, test, and increment clauses. -
+ Initializer is executed. Test is evaluated and must have a type that @@ -303,42 +344,34 @@ If Initializer declares a variable, that variable's scope extends through the end of Statement. For example: -
+ is equivalent to: -
+ Function bodies cannot be empty: -
+ Use instead: -
+ The Initializer may be omitted. Test may also be omitted, and if so, it is treated as if it evaluated to true. @@ -347,9 +380,7 @@ A foreach statement loops over the contents of an aggregate. -
+ Expression is evaluated. It must evaluate to an aggregate expression @@ -387,16 +418,14 @@ must be of int or uint type, it cannot be inout, and it is set to be the index of the array element. -
+ If the aggregate expression is a static or dynamic array of chars, wchars, or dchars, then the Type of @@ -405,9 +434,7 @@ In this manner any UTF array can be decoded into any UTF type: -
+ If the aggregate expression is an associative array, there @@ -435,16 +462,14 @@ array. It cannot be inout, and it is set to be the index of the array element. -
+ If the aggregate expression is a static or dynamic array, the elements are iterated over starting at index 0 and continuing @@ -456,11 +481,9 @@ If the aggregate is a struct or a class object, that struct or class must have an opApply function with the type: -
+ where Type matches the Type used in the foreach declaration of Identifier. Multiple ForeachTypes @@ -480,9 +503,7 @@ For example, consider a class that is a container for two elements: -
+ An example using this might be: -
+ which would print: @@ -530,9 +549,7 @@ Aggregates can be string literals, which can be accessed as char, wchar, or dchar arrays: -
+ which would print: @@ -557,9 +574,7 @@ inout can be used to update the original elements: -
+ which would print: @@ -588,9 +603,7 @@ reassigned or destructed while the foreach is iterating over the elements. -
+ A BreakStatement in the body of the foreach will exit the foreach, a ContinueStatement will immediately start the @@ -612,9 +625,7 @@ statements depending on the value of the switch expression. -
+ Expression is evaluated. The result type T must be of integral type or char[] or wchar[]. The result is @@ -659,9 +670,7 @@ can be nested within block statements; they do not have to be in the outermost block. For example, this is allowed: -
+ Like in C and C++, case statements 'fall through' to subsequent case values. A break statement will exit the switch BlockStatement. For example: -
+ will set x to 4 if i is 1. @@ -699,9 +706,7 @@ Note: Unlike C and C++, strings can be used in switch expressions. For example: -
+ For applications like command line switch processing, this can lead to much more straightforward code, being clearer and @@ -730,13 +735,11 @@ A continue aborts the current iteration of its enclosing loop statement, and starts the next iteration. -
+ continue executes the next iteration of its innermost enclosing while, for, or do loop. The increment clause is executed. @@ -761,13 +764,11 @@ A break exits the enclosing statement. -
+ break exits the innermost enclosing while, for, do, or switch statement, resuming execution at the statement following it. @@ -792,13 +793,11 @@ A return exits the current function and supplies its return value. -
+ Expression is required if the function specifies a return type that is not void. @@ -834,15 +833,13 @@ A goto transfers to the statement labelled with Identifier. -
+ The second form, goto default;, transfers to the innermost DefaultStatement of an enclosing SwitchStatement. @@ -869,42 +866,36 @@ The with statement is a way to simplify repeated references to the same object. - |