arrays...

Craig Schmackpfeffer craig at srs.UUCP
Tue May 3 23:42:33 AEST 1988


In article <5773 at sigi.Colorado.EDU> swarbric at tramp.Colorado.EDU (Frank Swarbrick) writes:
>Is there some reason why you can do:
>void foo(const int *bar);
>main()
>{
>   int ary[] = {1,2,3,4};
>
>   foo(ary);
>}
>but you can't do
>void foo(const int *bar);
>main()
>{
>   foo({1,2,3,4});
>}
>

Because {1,2,3,4} is not an array, but merely a convenient way of initializing 
an array.  

>main()
>{
>   char str[20];
>
>   strcpy(str,"This sucks!");
>}
>
>(no,
> strcpy(str,{'T','h','i','s',' ','s','u','c','k','s','\0'});
>doesn't work....)
>
>Frank Swarbrick (and his cat)           swarbric at tramp.Colorado.EDU

A string of characters within double quotes is represented as the array of
those characters followed by a terminating null byte.  It is defined to
return the address of the array.  The second attempt at the {} usage
doesn't work for the same reason the first try didn't work.
-- 
Craig Schmackpfeffer  @ S.R. Systems
{allegra,rutgers,ames}!rochester!srs!craig



More information about the Comp.lang.c mailing list