From 4399722291432415992 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,233d359668307510 X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 1995-03-17 01:55:27 PST Path: bga.com!news.sprintlink.net!news.clark.net!rahul.net!a2i!rfg.a2i!rfg From: "Ronald F. Guilmette" Newsgroups: comp.std.c++ Subject: Re: A language feature or quirk ? Date: 17 Mar 1995 09:44:40 GMT Organization: a2i network Lines: 30 Distribution: world Message-ID: <3kblm8$ndn@hustle.rahul.net> References: <3k2tn6$jig@mozo.cc.purdue.edu> NNTP-Posting-Host: bolero.rahul.net NNTP-Posting-User: rfg In article <3k2tn6$jig@mozo.cc.purdue.edu>, Surya N Kavuri wrote: > > void Print(char *s) { cout << s; } > >int main () >{ > Print("Hello"); // compiles; not an error! > > const char* s = "Hello"; > Print(s); // Compile time error as expected! > > cout << "What on earth is going on ?" << endl; > return 0; >} Character string literals (e.g. the first "Hello" above) have type char[] which decays (almost immediately, and in most contexts) to type `char*'. They DO NOT have type `const char[]' and thus they DO NOT decay into type `const char*'. The reason is historical, and is a matter of being backward compatible with ANSI/ISO C. -- -- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting ------------------- ---- E-mail: rfg@segfault.us.com ----------- Purveyors of Compiler Test ---- -------------------------------------------- Suites and Bullet-Proof Shoes -