#what is the difference between these characters in dlang ?
1 messages · Page 1 of 1 (latest)
what is the difference between c and w and d in dlang they all have the same size and the all can represent unicodes ?
UTF-8, UTF-16, UTF-32
they are encodings
for single characters char, wchar, dchar
they have much more limited ranges
and only dchar can represent all of Unicode using only one
so c w d are meant for char wchar and dchar only ?
the suffixes are for specifying what encoding the compiler should put a string literal into
Isn't autodecoding such a miss because this isnot true?
no, this is true
auto decoding is a problem because it does decode and hence change type
Oh...
what will the type be ?
Sizeof is returning size of a slice
wait is it you who created a language on github ?
i saw you
wait i don't understand what will the type be after using c or w or d ????
where should i use them ?
you used string, which is UTF-8 encoded string
but the literal is UTF-16 which is wstring
so there are 3 types of string not one
right
(w|d)string in D, is just a slice
pointer + length
its basically void*[2]
the type is the slice
what value it stores has nothing to do with it
D isn't C, array literals (like strings) actually have its length at runtime
to get the length of a slice use .length
on the variable, not the type
sizeof gives the size of a type
length gives the number of characters in the string
sizeof and length are not the same
indeed
8 + 8
pointer + length (size of pointer)
take a look under encoding
yeah you want .length
just to understand one thing bro
c
w
d
are only for
string
wstring
dstring
right ?
yes
OK BRO THANKS
For the most part, you should avoid these suffixes. Just use string literals without a suffix unless the compiler complains.
They are only needed when you want to enforce a specific encoding.
This is similar to taking sizeof of a pointer. You will get the size of the pointer, not what it points to.
if you did (cast(ubyte[]) "thing").length you'd see differences with the various stirng suffixe
Try ```d
writeln(typeof(a[0]).sizeof);
writeln(typeof(b[0]).sizeof);
writeln(typeof(c[0]).sizeof);
The elements of the string have different sizes. Thats the difference.