---- START NEW MESSAGE --- Received: from cherry.ease.lsoft.com [209.119.0.109] by dpmail10.doteasy.com with ESMTP (SMTPD32-8.05) id A6F611B00068; Fri, 30 Jan 2004 19:54:30 -0800 Received: from PEAR.EASE.LSOFT.COM (209.119.0.19) by cherry.ease.lsoft.com (LSMTP for Digital Unix v1.1b) with SMTP id <0.00CC5DC4@cherry.ease.lsoft.com>; Fri, 30 Jan 2004 22:54:15 -0500 Received: from MITVMA.MIT.EDU by MITVMA.MIT.EDU (LISTSERV-TCP/IP release 1.8e) with spool id 1837 for PICLIST@MITVMA.MIT.EDU; Fri, 30 Jan 2004 22:54:09 -0500 Received: from MITVMA (NJE origin SMTP@MITVMA) by MITVMA.MIT.EDU (LMail V1.2d/1.8d) with BSMTP id 9837; Fri, 30 Jan 2004 22:52:15 -0500 Received: from out009.verizon.net [206.46.170.131] by mitvma.mit.edu (IBM VM SMTP Level 430) via TCP with SMTP ; Fri, 30 Jan 2004 22:52:14 EST X-Comment: mitvma.mit.edu: Mail was sent by out009.verizon.net Received: from dell8100 ([141.149.140.164]) by out009.verizon.net (InterMail vM.5.01.06.06 201-253-122-130-106-20030910) with ESMTP id <20040131035217.LALV11926.out009.verizon.net@dell8100> for ; Fri, 30 Jan 2004 21:52:17 -0600 References: <401A3296.29642.4FB3D9C@localhost> <401A8392.10961.637A10C@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Authentication-Info: Submitted using SMTP AUTH at out009.verizon.net from [141.149.140.164] at Fri, 30 Jan 2004 21:52:15 -0600 Message-ID: <004401c3e7ad$9aae0480$6500a8c0@dell8100> Date: Fri, 30 Jan 2004 22:48:00 -0500 Reply-To: pic microcontroller discussion list Sender: pic microcontroller discussion list From: Bob Ammerman Subject: Re: [PIC]: Hitech PICCLITE state machine optimization To: PICLIST@MITVMA.MIT.EDU Precedence: list X-RCPT-TO: Status: U X-UIDL: 371856634 ----- Original Message ----- From: "Andrew Warren" To: Sent: Friday, January 30, 2004 7:17 PM Subject: Re: [PIC]: Hitech PICCLITE state machine optimization > Herbert Graf wrote: > > > if ((ISR_state == 0 && ISR_charBuf == 'G') > > || (ISR_state == 1 && ISR_charBuf == 'F') > > || (ISR_state == 2 && ISR_charBuf == 'D') > > || (ISR_state == 3 && ISR_charBuf == 'V') > > || (ISR_state == 4 && ISR_charBuf == 'W') > > || (ISR_state == 5 && ISR_charBuf == 'H') > > || (ISR_state == 6 && ISR_charBuf == 'Y') > > || (ISR_state == 7 && ISR_charBuf == 'Z')) > > ISR_state++; > > > > Any idea how I might restructure my thinking or code to make this a > > little tamer? > > Make a constant array of 8 characters; initialize it with G, F, > D, V, W, H, Y, Z. Then: > > if (ISR_charBuf == array[ISR_state]) ISR_state++; > > -Andy Or even: if (ISR_charBuf == "GFDVWWHYZ"[ISR_state]) ISR_state++ Or amazingly: if (ISR_charBuf == ISR_state["GFDVWHYZ"]) ISR_state++ Both of the above are legal ANSI "C" (and mean the same thing). With PIC C compilers YMMV. Note that in ANSI 'C', x[y] is _defined_ to be *(x+y) Bob Ammerman RAm Systems -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body .