[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [leafnode-list] Compiler warnings (again)
krasel@xxxxxxxxxxxxxxxxxxxxxxxxxxxx (Cornelius Krasel) writes:
> int count( void ) {
> struct newsgroup * g;
> int i;
>
> g = active;
> i = 0;
> while ( g->name ) {
> i++;
> *(g++); /* let g point to next element of array */
> }
> return i;
> }
>
> Unfortunately, gcc barfs on the *(g++); line with "warning: value
> computed is not used".
>
> What am I doing wrong?
1. (not the cause for compiler warning, just standard ranting) you're
still sticking to global variables ;) count should be passed the
"active" which it is supposed to count, such as int count (struct
newsgroup *active);
2. (actual problem) you calculate a dereference of that g pointer (*
operator), but don't use it afterwards. Your compiler thus warns of
unnecessary work.
What the compiler does with "*(g++);" is: "*g; g++;". *g is not assigned
or indexed into anywhere, the compiler says "not used".
Do
g++;
instead of
*(g++);
and it'll be fine. You can also omit all the i counter stuff and write
return (g - active)/sizeof (struct newsgroup *);
(sizeof (void *) should be equivalent, but is less obvious);
NB: untested
/* WHERE DOES active COME FROM? */
int count(void) {
struct newsgroup * g=active;
while (g->name) {
g++;
}
return (g - active) / sizeof(struct newsgroup *);
}
--
Matthias Andree
Hi! I'm the infamous .signature virus!
Copy me into your ~/.signature to help me spread!
--
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list