Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > String literals
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 19 Topic 9776 of 9909
Post > Topic >>

String literals

by anubhav.saxena@[EMAIL PROTECTED] Jul 10, 2008 at 03:28 AM

Hi,

I have a problem in understanding what is wrong with the function call
'fun1(pc1)' in the code below. I am sure I am missing something really
basic and silly in my understanding.

void fun1(const char (& arr)[5])
{
	cout << sizeof(arr);
}
int main(int argc, char **argv){
	const char *pc1 = "2008";
	const char pc2[] = "2008";
	fun1(pc1);
	fun1(pc2);
}

All of VS2008, g++ and Comeau give error in the compilation stating
that it is not possible to convert 'const char *' to 'const char (&)
[5]'

2.13.4/1 states the following "An ordinary string literal has type
``array of n const char'' and static storage duration (basic.stc),
where n is the size of the string as defined below, and is initialized
with the given characters.".

With this understanding I think that fun1(pc1) call should also be
successful as is fun1(pc2)

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 19 Posts in Topic:
String literals
anubhav.saxena@[EMAIL PRO  2008-07-10 03:28:06 
Re: String literals
Alberto Ganesh Barbati &l  2008-07-10 14:05:30 
Re: String literals
Oncaphillis <oncaphill  2008-07-10 14:01:33 
Re: String literals
Erek Speed <melink14@[  2008-07-10 14:02:20 
Re: String literals
Francis Glassborow <fr  2008-07-10 14:04:15 
Re: String literals
Pavel Minaev <int19h@[  2008-07-10 14:04:52 
Re: String literals
Ulrich Eckhardt <eckha  2008-07-10 14:05:44 
Re: String literals
Martin Bonner <martinf  2008-07-10 14:05:55 
Re: String literals
anubhav.saxena@[EMAIL PRO  2008-07-10 14:10:45 
Re: String literals
Bart van Ingen Schenau &l  2008-07-10 14:17:14 
Re: String literals
Mathias Gaunard <loufo  2008-07-10 14:10:26 
Re: String literals
Thomas Maeder <maeder@  2008-07-10 14:16:29 
Re: String literals
Chris Uzdavinis <cuzda  2008-07-10 14:28:06 
Re: String literals
Alberto Ganesh Barbati &l  2008-07-10 20:28:06 
Re: String literals
anubhav.saxena@[EMAIL PRO  2008-07-11 14:07:56 
Re: String literals
Francis Glassborow <fr  2008-07-11 14:14:56 
Re: String literals
Maxim Yegorushkin <max  2008-07-11 14:12:42 
Re: String literals
Oncaphillis <oncaphill  2008-07-11 18:26:48 
Re: String literals
Alberto Ganesh Barbati &l  2008-07-12 03:58:25 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 20 4:18:05 CDT 2008.