confusion with char *a and char a[NUM]
Dan Salomon
salomon at ccu.umanitoba.ca
Wed Dec 5 08:48:45 AEST 1990
In article <7656 at umd5.umd.edu> jjk at astro.umd.edu( Jim Klavetter) writes:
>
>I can have two identical files except that one I declare a to be
> char a[NUM]
>and the other has
> char *a with a malloc of NUM+1 characters.
>
...
>However, if I have
> a=strchr(string, ":");
>I get the error message
> 121: incompatible types in assignment
>
No big mystery.
char a[NUM];
declares "a" to be a constant pointer to an array of char that points
to the region allocated by the compiler.
Hence you cannot change its value.
char *a;
declares a to be a variable pointer to an array of char.
This treatment allows the optimization of array accesses with
constant subscripts.
--
Dan Salomon -- salomon at ccu.UManitoba.CA
Dept. of Computer Science / University of Manitoba
Winnipeg, Manitoba, Canada R3T 2N2 / (204) 275-6682
More information about the Comp.lang.c
mailing list