Date: Wed, 6 Nov 2002 10:59:29 -0800 From: Jordan K Hubbard <jkh@queasyweasel.com> To: Marc Olzheim <marcolz@stack.nl> Cc: hackers@FreeBSD.ORG Subject: Re: /usr/src/ed/bin/re.c:99 Message-ID: <E0C3C3FE-F1B9-11D6-A916-000393BB9222@queasyweasel.com> In-Reply-To: <20021106164653.GA95733@stack.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E0C3C3FE-F1B9-11D6-A916-000393BB9222>