M
mdh
Hi All,
I have a couple of questions regarding the discussions on page 124 of
k&r.
1)
This references functions working with complicated declarations in C.
before main(...,...){}, (in file main.c), an enum is defined thus.
enum {NAME, PARENS, BRACKETS};
int gettoken(){......}
refers to this with a return line thus.
return tokentype = PARENS;
Now, I am assuming that gettoken and main are compiled in the same
file?
I am trying to compile "gettoken" in my "foo.c" file. Hence I wish to
ref the enum from there.
I have tried this.
Giving the enum an identifier,
"enum syntax {NAME, PARENS, BRACKETS};"
and then declaring it in foo.c thus.
extern enum syntax; but this gives a warning "useless storage class
specifier in empty declaration "
2) staying with the "extern" theme.
A char array is defined in main.c
" char token[10]; "
Again referenced from foo.c using syntax "extern char token".
This in of itself does not give a warning, ( which I think is
expected) but this line does.
char *p = token " initialization makes pointer from integer without a
cast"
I would have thought that 'token' is changed to a ptr to char of the
first element in the array, so not quite sure what or if to try and
correct this.
Thanks in advance....and holding my head...there have been some testy
responses lately...so hopefully I do not fit those stereoptypes!!
I have a couple of questions regarding the discussions on page 124 of
k&r.
1)
This references functions working with complicated declarations in C.
before main(...,...){}, (in file main.c), an enum is defined thus.
enum {NAME, PARENS, BRACKETS};
int gettoken(){......}
refers to this with a return line thus.
return tokentype = PARENS;
Now, I am assuming that gettoken and main are compiled in the same
file?
I am trying to compile "gettoken" in my "foo.c" file. Hence I wish to
ref the enum from there.
I have tried this.
Giving the enum an identifier,
"enum syntax {NAME, PARENS, BRACKETS};"
and then declaring it in foo.c thus.
extern enum syntax; but this gives a warning "useless storage class
specifier in empty declaration "
2) staying with the "extern" theme.
A char array is defined in main.c
" char token[10]; "
Again referenced from foo.c using syntax "extern char token".
This in of itself does not give a warning, ( which I think is
expected) but this line does.
char *p = token " initialization makes pointer from integer without a
cast"
I would have thought that 'token' is changed to a ptr to char of the
first element in the array, so not quite sure what or if to try and
correct this.
Thanks in advance....and holding my head...there have been some testy
responses lately...so hopefully I do not fit those stereoptypes!!