From owner-freebsd-hackers Wed Nov 6 10:59:23 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D64E537B401 for ; Wed, 6 Nov 2002 10:59:21 -0800 (PST) Received: from jkh-gw.queasyweasel.com (adsl-64-173-3-158.dsl.sntc01.pacbell.net [64.173.3.158]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3070E43E42 for ; Wed, 6 Nov 2002 10:59:21 -0800 (PST) (envelope-from jkh@queasyweasel.com) Received: from queasyweasel.com (jkh@narcissus.freebsd.com [64.173.15.99]) by jkh-gw.queasyweasel.com (8.12.6/8.12.5) with ESMTP id gA6Ivx3L044399; Wed, 6 Nov 2002 10:58:00 -0800 (PST) (envelope-from jkh@queasyweasel.com) Date: Wed, 6 Nov 2002 10:59:29 -0800 Subject: Re: /usr/src/ed/bin/re.c:99 Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v548) Cc: hackers@FreeBSD.ORG To: Marc Olzheim From: Jordan K Hubbard In-Reply-To: <20021106164653.GA95733@stack.nl> Message-Id: Content-Transfer-Encoding: 7bit X-Mailer: Apple Mail (2.548) Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG It's legal, though one would have to know what the author was thinking (or at least read the surrounding code) before stating that it's also "correct". It's legal because, unlike the example given in that FAQ entry you referenced, there's an implicit ordering in the expression that even the most aggressive compiler optimizer couldn't change. In order for the value of parse_char_class() to be returned, its arguments must obviously be evaluated first and that means that ++nd will always occur before the assignment operator. Stylistically, of course, it's ugly as hell and would be dinged by any CS professor grading this as homework. Is nd a local variable? If so, why didn't the author simply pass "nd + 1" as the argument since the extra assignment from the unary operator is essentially wasted cycles? Or is nd a global variable also referenced from within parse_char_class(), thus requiring the use of the ++ operator and if so, then why didn't parse_char_class() simply side-effect the global rather than forcing a re-assignment from within the parent function? Indeed, why is nd a global at all? These and other questions are left as an exercise for the reader. :-) - Jordan On Wednesday, November 6, 2002, at 08:46 AM, Marc Olzheim wrote: > .. > if ((nd = parse_char_class(++nd)) == NULL) { > .. > > Hmmm... is this legal ? > > http://www.eskimo.com/~scs/C-faq/q3.1.html seems to tell otherwise... > > Zlo > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message > -- Jordan K. Hubbard Engineering Manager, BSD technology group Apple Computer To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message