2 In external documents you can find info on
3 operator overloading and generic programming with template
4 classes and local typedefs.
6 1. Functions returning References
7 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 Functions can return a reference to a type.
10 In this case, the function call is an lvalue
11 and can be in the left part of an assignment.
21 return extended + n - 100;
26 nth (10) = nth (20) = -1;
29 A function returning a reference, in reallity returns
30 a pointer and the lwc compiler adjusts that the pointer
31 is lvaluated in the expression. In the return statement
32 a function returning a reference may return an object or
33 a pointer to an object. The lwc compiler will make
34 the neccessary adjustments.
36 Overloading the array operator for structures in
37 simplified with references:
41 float& operator [] (int i)
52 2. Boolean toggle operator
53 ~~~~~~~~~~~~~~~~~~~~~~~~~~
55 lwc supports the exclamation operator '!!' in prefix
56 and postfix mode. This operator will perform a boolean
57 negation to the operand (which must be modifiable therefore).
58 In the prefix mode, the result of the expression will
59 be the negated value, while in postfix the negation will
72 3. Class Declaration Qualifiers
73 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75 When the declaration qualifiers (specifiers) 'static', 'inline',
76 'virtual' and 'auto' precede the declaration of a class,
77 they apply for all member functions. In the example below,
78 all member functions of 'A' will have internal linkage:
85 'static' is useful to the underlying C compiler to inform internal
86 linkage (may save some space in the object file).
87 'inline' is the hint that the C compiler should attempt to inline.
88 'virtual' means that all member functions are virtual!
89 'auto' means that all the functions are automatically redefined
90 in each derrived object!
92 those qualifiers are not inherited to member functions declared
96 4. Proper destruction (II)
97 ~~~~~~~~~~~~~~~~~~~~~~~~~~
99 In the cases of virtual inheritance, it is normally impossible to
100 delete an object by the address of the base object. It is also
101 impossible to delete an object in multiple inheritance by the
102 address of a base object not first in inheritance. These will
103 produce a segfault (in c++ too):
110 class V1 : virtual V {int i;}
111 class V2 : virtual V {int j;}
112 class VV : V1, V2 {};
123 lwc calls free() with the address returned from the
124 destructor function. So these can be resolved with auto
128 auto virtual ~A () {}
133 destructors, transparently return 'this'. If you return
134 some other value, you're on your own. This could be useful?
137 5. tmp structure addresses
138 ~~~~~~~~~~~~~~~~~~~~~~~~~~
140 This is useful internally for the operator overloading,
141 but it works in general. Sample case:
161 Normally, because structures are passed by reference,
162 foo really takes a pointer. But the memory of the structure
163 returned by baz, is totally temporary and the C compiler
164 will refuse to get it's address. lwc works around this
165 by calling an intermediate 'trampoline' function.
168 6. linkonce specifier
169 ~~~~~~~~~~~~~~~~~~~~~
171 lwc supports the storage class specifier 'linkonce' for
172 functions. A function declared linkonce, will have a special
173 linkage in its own section.