@@ -840,7 +840,8 @@ $(H2 $(LNAME2 data-type-compatibility, Data Type Compatibility))
840
840
841
841
$(TROW
842
842
$(ARGS $(I type)$(B [)$(I dim)$(B ])),
843
- $(ARGS $(I type)$(B [)$(I dim)$(B ]))
843
+ $(ARGS $(I type)$(B [)$(I dim)$(B ]) for a variable/field declaration,
844
+ or $(DDSUBLINK spec/interfaceToC, passing_d_array, use `ref` for function parameter))
844
845
)
845
846
846
847
$(TROW
@@ -850,7 +851,7 @@ $(H2 $(LNAME2 data-type-compatibility, Data Type Compatibility))
850
851
851
852
$(TROW
852
853
$(ARGS $(I type)$(B [])),
853
- $(ARGS no equivalent)
854
+ $(ARGS no `extern (C++)` equivalent, $(RELATIVE_LINK2 dynamic-arrays, see below) )
854
855
)
855
856
856
857
$(TROW
@@ -872,6 +873,48 @@ $(H2 $(LNAME2 data-type-compatibility, Data Type Compatibility))
872
873
$(P These equivalents hold when the D and C++ compilers used are companions
873
874
on the host platform.)
874
875
876
+ $(H3 $(LNAME2 dynamic-arrays, Dynamic Arrays))
877
+
878
+ $(P These are not supported for `extern (C++)`. For `extern (C)`, they
879
+ are equivalent to a struct template. For example:)
880
+
881
+ ---
882
+ extern (C) const(char)[] slice;
883
+ ---
884
+
885
+ $(P `dmd -HC` generates the following C++ declaration:)
886
+
887
+ ```
888
+ extern "C" _d_dynamicArray< const char > slice;
889
+ ```
890
+ $(P `_d_dynamicArray` is generated as follows:)
891
+
892
+ ```
893
+ /// Represents a D [] array
894
+ template<typename T>
895
+ struct _d_dynamicArray final
896
+ {
897
+ size_t length;
898
+ T *ptr;
899
+
900
+ _d_dynamicArray() : length(0), ptr(NULL) { }
901
+
902
+ _d_dynamicArray(size_t length_in, T *ptr_in)
903
+ : length(length_in), ptr(ptr_in) { }
904
+
905
+ T& operator[](const size_t idx) {
906
+ assert(idx < length);
907
+ return ptr[idx];
908
+ }
909
+
910
+ const T& operator[](const size_t idx) const {
911
+ assert(idx < length);
912
+ return ptr[idx];
913
+ }
914
+ };
915
+ ```
916
+
917
+
875
918
$(H2 $(LNAME2 packing-and-alignment, Packing and Alignment))
876
919
877
920
$(P D structs and unions are analogous to C's.
0 commit comments