#what is the difference between these characters in dlang ?

1 messages · Page 1 of 1 (latest)

languid terrace
#

what is the difference between c and w and d in dlang they all have the same size and the all can represent unicodes ?

ornate osprey
#

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

languid terrace
#

so c w d are meant for char wchar and dchar only ?

ornate osprey
#

the suffixes are for specifying what encoding the compiler should put a string literal into

clear kiln
ornate osprey
#

no, this is true

#

auto decoding is a problem because it does decode and hence change type

languid terrace
#

but

#

wait a second

clear kiln
#

Oh...

languid terrace
#

what will the type be ?

timid elk
#

Sizeof is returning size of a slice

languid terrace
#

i saw you

timid elk
#

Which is a pointer + length

#

I do have a language

languid terrace
#

yeah as i expected

#

it is you

languid terrace
#

where should i use them ?

ornate osprey
#

you used string, which is UTF-8 encoded string

#

but the literal is UTF-16 which is wstring

languid terrace
#

how can i use wstring ?

#

is it from a library ?

ornate osprey
#

no, its an alias just like string

#

just using wchar instead of char

languid terrace
#

so there are 3 types of string not one

ornate osprey
#

right

#

(w|d)string in D, is just a slice

#

pointer + length

#

its basically void*[2]

languid terrace
#

they all have the same size

#

where is the difference ????????????????????

ornate osprey
#

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

languid terrace
#

sizeof gives the size of a type

#

length gives the number of characters in the string

#

sizeof and length are not the same

ornate osprey
#

indeed

languid terrace
#

so i am still confused

#

maybe wstring is an old version of string ?

ornate osprey
#

no

#

just a different encoding

languid terrace
#

how can i see that encoding ???????

ornate osprey
#

8 + 8

#

pointer + length (size of pointer)

#

take a look under encoding

languid terrace
ornate osprey
#

yeah you want .length

languid terrace
#

just to understand one thing bro

c
w
d

are only for

string
wstring
dstring

right ?

ornate osprey
#

yes

languid terrace
#

OK BRO THANKS

quaint reef
#

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.

timid elk
rich belfry
#

if you did (cast(ubyte[]) "thing").length you'd see differences with the various stirng suffixe

somber glade
#

The elements of the string have different sizes. Thats the difference.