mixing pointers and arrays
cobb at csu-cs.UUCP
cobb at csu-cs.UUCP
Fri Jul 29 06:11:27 AEST 1983
Consider the two routines:
extern char *yytext;
main ()
{
stat ();
printf ("%s\n",*yytext);
}
and
char yytext [10];
stat ()
{
yytext [0] = 'y';
yytext [1] = 'e';
yytext [2] = 'a';
yytext [3] = 'r';
yytext [4] = '\0';
}
These two routines exist in different modules, and are compiled
separately and then linked and loaded. However, every time I try to
execute the routine, I get an execution error. From reading the C
manual, the implication is that yytext is implemented as a pointer
to some storage locations, and can therefore be treated as such. This
is reinforced by the legal program segment
.
.
.
char ch [n];
char *chptr;
chptr = ch;
.
.
which results in chptr being assigned the base location of the array
'ch'. Why then do the first routines blow up?
Thanks
S. Cobb
!hao!csu-cs!cobb
More information about the Comp.lang.c
mailing list