www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - char => char[]

reply bobef <bobef lessequal.com> writes:
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...
Feb 16 2006
next sibling parent Oskar Linde <olREM OVEnada.kth.se> writes:
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.
Feb 16 2006
prev sibling next sibling parent Hasan Aljudy <hasan.aljudy gmail.com> writes:
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 assuming yourChar is a variable of type char
Feb 16 2006
prev sibling parent =?UTF-8?B?SnVsaW8gQ8Opc2FyIENhcnJhc2NhbCBVcnF1aWpv?= writes:
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
Feb 16 2006