Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 16, 2006 char => char[] | ||||
---|---|---|---|---|
| ||||
cannot cast char to char[] cannot cast char to char[1] this is what DMD says, but I don't see what's the big deal. It is obvious that char is char[1]. Maybe there is technical reason... |
February 16, 2006 Re: char => char[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to bobef | bobef wrote:
> cannot cast char to char[]
> cannot cast char to char[1]
>
> this is what DMD says, but I don't see what's the big deal. It is obvious that char is char[1]. Maybe there is technical reason...
Your char may only live in a register in the cpu. In order to cast it to a single element array, you need to allocate a memory location to store it.
|
February 16, 2006 Re: char => char[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to bobef | bobef wrote:
> cannot cast char to char[]
> cannot cast char to char[1]
>
> this is what DMD says, but I don't see what's the big deal. It is obvious that char is char[1]. Maybe there is technical reason...
I think it can be done with
# "" ~ yourChar
assuming yourChar is a variable of type char
|
February 17, 2006 Re: char => char[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to bobef | bobef wrote:
> cannot cast char to char[]
> cannot cast char to char[1]
>
> this is what DMD says, but I don't see what's the big deal. It is obvious that char is char[1]. Maybe there is technical reason...
Not quite. While a char is an utf8 code point. char[1] its actually a structure like this:
char c = 'a';
struct CharArr1
{
char* ptr = &c;
size_t length = 1;
}
You can convert a char to a char[] with this code:
char[] charArr1 = (&c)[0..1];
Julio César Carrascal Urquijo
|
Copyright © 1999-2021 by the D Language Foundation