Re: switch statement and numeric constants
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: switch statement and numeric constants

From: Schelte Bron <nospam@wanadoo.nl>
Date: Fri May 27 2005 - 15:58:40 CEST

On 05/27/05 14:28, Christopher Nelson wrote:
> ...
> binary scan $bpdu "S c c c a*" \
> a(protocol) a(rstpVersion) a(type) a(flags) bpdu
>
> if {$a(protocol) != 0 } {
> error "Invalid protocol"
> }
> switch -- $a(type) {
> 0 {
> set a(type) "CFG"
> }
> 0x80 {
> set a(type) "TCN"
> }
> 2 {
> set a(type) "RST"
> }
> default {
> error "Unknown BPDU type"
> }
> }
> ...
>
You are aware that the switch command does string matching? This means
that the 0x80 pattern will never match the value of a variable that has
been set by binary scan c. Your pattern should probably be "-128".

Schelte.

-- 
set Reply-To [string map {nospam schelte} $header(From)]
Received on Thu Sep 29 14:19:29 2005