lkml.org 
[lkml]   [2004]   [Dec]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectdoubt about "switch" - default case in af_inet.c
Hi all,

I'm a newbie to the Linux. I'm using 2.6.8 kernel.
In /usr/src/linux/net/ipv4/af_inet.c I came across this...
<code>
switch (sock->state) {
default:
//do something..
goto out;
case SS_CONNECTED:
//do something..
goto out;
case SS_CONNECTING:
//do something..
break;
case SS_UNCONNECTED:
//do something..
break;
}
</code>

Is there any advantage in having 'default' as the first case?
My understanding is that it will be useful only when 'default' is the
most likely case (in general).

Even then, my doubt: How will compiler (say gcc) implement 'default'
as the first value? Program is supposed to see all the cases and then
decide 'default'. Is this correct?

So, is this the best way to do it? please clarify..

Thanks,
Phani
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:08    [W:0.027 / U:2.984 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site