From: Juan C. A. B. <jc...@ro...> - 2000-10-12 16:42:32
|
At 09:08 PM 10/11/2000 -0700, you wrote: >unsigned char String[] = (unisgned char [])"Hello" ; > >In C++ I get: ANSI C++ forbids casting to an array type Well, In general, using an unbounded array, except in declarations of global variables, indicates that it's actually a pointer. Thus, "unsigned char []" is quite identical to "unsigned char *". This one should work, though (once the "unisgned" typo is fixed ;-): unsigned char *String = (unisgned char *)"Hello"; This is very clear in the two flavors of main(): int main(int argc, char **argv); int main(int argc, char *argv[]); Which are both available and identical, even in strong-typed C++. Another thing to note is that types "char", "unsigned char" and "signed char" are all different as far as a compliant ANSI C++ compilers are concerned. The default signed-ness of the "char" type is just a thing to tell the compiler how to do arithmetic with chars. It is NOT making it the same type as the corresponding "unsigned char" or "signed char" type. It's the same as "int" and "long" in PC computers. They are both signed 32-bit integers, but they are distinct types nevertheless. Anther thing that you can do is: unsigned char String[] = { 'H', 'e', 'l', 'l', 'o', 0 }; But it's ugly. Also note that, in MSVC, the following is, for some reason, accepted: unsigned char String[] = "Hello"; Salutaciones, JCAB --------------------------------------------------------------------- Juan Carlos "JCAB" Arevalo Baeza | http://www.roningames.com Senior Technology programmer | mailto:jc...@ro... Ronin Entertainment | ICQ: 10913692 (my opinions are only mine) JCAB's Rumblings: http://www.metro.net/jcab/Rumblings/html/index.html |