* [9fans] Compiler question
@ 2005-09-19 19:27 ISHWAR RATTAN
2005-09-19 19:44 ` Russ Cox
2005-09-19 19:45 ` Russ Cox
0 siblings, 2 replies; 10+ messages in thread
From: ISHWAR RATTAN @ 2005-09-19 19:27 UTC (permalink / raw)
To: 9fans
The compiler complains about line 8:
warning: file.c: set and not used: tmp
-ishwar
----
1 void freelist(lnode **list)
2 {
3 lnode *tmp;
4
5 while( *list != nil){
6 tmp = *list;
7 *list = (*list)->next;
8 tmp = freenode(tmp);
9 }
*list = nil;
}
---
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [9fans] Compiler question
2005-09-19 19:27 [9fans] Compiler question ISHWAR RATTAN
@ 2005-09-19 19:44 ` Russ Cox
2005-09-19 23:26 ` David Leimbach
2005-09-19 19:45 ` Russ Cox
1 sibling, 1 reply; 10+ messages in thread
From: Russ Cox @ 2005-09-19 19:44 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
> 1 void freelist(lnode **list)
> 2 {
> 3 lnode *tmp;
> 4
> 5 while( *list != nil){
> 6 tmp = *list;
> 7 *list = (*list)->next;
> 8 tmp = freenode(tmp);
> 9 }
> *list = nil;
> }
> The compiler complains about line 8:
> warning: file.c: set and not used: tmp
And rightly so!
Russ
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [9fans] Compiler question
2005-09-19 19:27 [9fans] Compiler question ISHWAR RATTAN
2005-09-19 19:44 ` Russ Cox
@ 2005-09-19 19:45 ` Russ Cox
2005-09-19 20:11 ` Joel Salomon
1 sibling, 1 reply; 10+ messages in thread
From: Russ Cox @ 2005-09-19 19:45 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
> The compiler complains about line 8:
> warning: file.c: set and not used: tmp
>
> 1 void freelist(lnode **list)
> 2 {
> 3 lnode *tmp;
> 4
> 5 while( *list != nil){
> 6 tmp = *list;
> 7 *list = (*list)->next;
> 8 tmp = freenode(tmp);
> 9 }
> *list = nil;
> }
The compiler is telling you that line 8 might as well read:
> 8 freenode(tmp);
The value you store in tmp is never used.
Russ
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [9fans] Compiler question
2005-09-19 19:45 ` Russ Cox
@ 2005-09-19 20:11 ` Joel Salomon
2005-09-19 21:08 ` ISHWAR RATTAN
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Joel Salomon @ 2005-09-19 20:11 UTC (permalink / raw)
To: Russ Cox, Fans of the OS Plan 9 from Bell Labs
On 9/19/05, Russ Cox <rsc@swtch.com> wrote:
> The compiler is telling you that line 8 might as well read:
>
> > 8 freenode(tmp);
>
> The value you store in tmp is never used.
>
Does the compiler know that about freenode()?
--Joel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [9fans] Compiler question
2005-09-19 20:11 ` Joel Salomon
@ 2005-09-19 21:08 ` ISHWAR RATTAN
2005-09-20 0:10 ` Rob Pike
2005-09-19 21:23 ` rog
2005-09-19 21:54 ` Ronald G Minnich
2 siblings, 1 reply; 10+ messages in thread
From: ISHWAR RATTAN @ 2005-09-19 21:08 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
On Mon, 19 Sep 2005, Joel Salomon wrote:
> On 9/19/05, Russ Cox <rsc@swtch.com> wrote:
> The compiler is telling you that line 8 might as well read:
>
> > 8 freenode(tmp);
>
> The value you store in tmp is never used.
>
> Does the compiler know that about freenode()?
Well the freenode function is:
lnode *
freenode(lonode *ptr)
{
if (ptr != nil) {
free((void *)ptr);
ptr = nil;
}
return ptr;
}
So ptr = freenode(ptr);
looks resonable way to call.
-ishwar
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [9fans] Compiler question
2005-09-19 20:11 ` Joel Salomon
2005-09-19 21:08 ` ISHWAR RATTAN
@ 2005-09-19 21:23 ` rog
2005-09-19 21:54 ` Ronald G Minnich
2 siblings, 0 replies; 10+ messages in thread
From: rog @ 2005-09-19 21:23 UTC (permalink / raw)
To: 9fans
> On 9/19/05, Russ Cox <rsc@swtch.com> wrote:
> > > 8 freenode(tmp);
> >
> > The value you store in tmp is never used.
>
> Does the compiler know that about freenode()?
the original source had "tmp = freenode(tmp)" (at the end of the loop)
but tmp was immediately assigned to at the start of the loop,
losing the value stored; hence the compiler warning. the semantics of
freenode are irrelevant.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [9fans] Compiler question
2005-09-19 20:11 ` Joel Salomon
2005-09-19 21:08 ` ISHWAR RATTAN
2005-09-19 21:23 ` rog
@ 2005-09-19 21:54 ` Ronald G Minnich
2 siblings, 0 replies; 10+ messages in thread
From: Ronald G Minnich @ 2005-09-19 21:54 UTC (permalink / raw)
To: joelcsalomon, Fans of the OS Plan 9 from Bell Labs; +Cc: Russ Cox
joel, take your loop, and unroll it by hand, for 2 or 3 iterations, and
you will see the problem.
ron
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [9fans] Compiler question
2005-09-19 19:44 ` Russ Cox
@ 2005-09-19 23:26 ` David Leimbach
0 siblings, 0 replies; 10+ messages in thread
From: David Leimbach @ 2005-09-19 23:26 UTC (permalink / raw)
To: Russ Cox, Fans of the OS Plan 9 from Bell Labs
On 9/19/05, Russ Cox <rsc@swtch.com> wrote:
> > 1 void freelist(lnode **list)
> > 2 {
> > 3 lnode *tmp;
> > 4
> > 5 while( *list != nil){
> > 6 tmp = *list;
> > 7 *list = (*list)->next;
> > 8 tmp = freenode(tmp);
> > 9 }
> > *list = nil;
> > }
>
> > The compiler complains about line 8:
> > warning: file.c: set and not used: tmp
>
> And rightly so!
>
Yep, line 8's assignment gets wiped out by line 6's assignment on the
second iteration.
May as well just read.
freenode(tmp); on line 8.
The compiler is good for finding this :)
> Russ
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [9fans] Compiler question
2005-09-19 21:08 ` ISHWAR RATTAN
@ 2005-09-20 0:10 ` Rob Pike
2005-09-20 0:19 ` ISHWAR RATTAN
0 siblings, 1 reply; 10+ messages in thread
From: Rob Pike @ 2005-09-20 0:10 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
the return value is always nil. why bother returning it?
-rob
On 9/20/05, ISHWAR RATTAN <rattan@cps.cmich.edu> wrote:
>
>
> On Mon, 19 Sep 2005, Joel Salomon wrote:
>
> > On 9/19/05, Russ Cox <rsc@swtch.com> wrote:
> > The compiler is telling you that line 8 might as well read:
> >
> > > 8 freenode(tmp);
> >
> > The value you store in tmp is never used.
> >
> > Does the compiler know that about freenode()?
>
> Well the freenode function is:
>
> lnode *
> freenode(lonode *ptr)
> {
> if (ptr != nil) {
> free((void *)ptr);
> ptr = nil;
> }
> return ptr;
> }
>
> So ptr = freenode(ptr);
>
> looks resonable way to call.
>
> -ishwar
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [9fans] Compiler question
2005-09-20 0:10 ` Rob Pike
@ 2005-09-20 0:19 ` ISHWAR RATTAN
0 siblings, 0 replies; 10+ messages in thread
From: ISHWAR RATTAN @ 2005-09-20 0:19 UTC (permalink / raw)
To: Rob Pike, Fans of the OS Plan 9 from Bell Labs
On Tue, 20 Sep 2005, Rob Pike wrote:
> the return value is always nil. why bother returning it?
A student came by with the code and question. Next time I sall
be able to explain.
-ishwar
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2005-09-20 0:19 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-19 19:27 [9fans] Compiler question ISHWAR RATTAN
2005-09-19 19:44 ` Russ Cox
2005-09-19 23:26 ` David Leimbach
2005-09-19 19:45 ` Russ Cox
2005-09-19 20:11 ` Joel Salomon
2005-09-19 21:08 ` ISHWAR RATTAN
2005-09-20 0:10 ` Rob Pike
2005-09-20 0:19 ` ISHWAR RATTAN
2005-09-19 21:23 ` rog
2005-09-19 21:54 ` Ronald G Minnich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).