Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: index and rindex question... Message-ID: <15826@haddock.ima.isc.com> Date: 1 Feb 90 16:33:33 GMT References: <11716.25C6818B@urchin.fidonet.org> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 13 In article <11716.25C6818B@urchin.fidonet.org> Bob.Stout@p6.f506.n106.z1.fidonet.org (Bob Stout) writes: >Based on this usage, I use: >#define index(s,c) ((strchr((s),(c))) ? (size_t)(strchr((s),(c))-(s)) : -1) >#define rindex(s,c) ((strrchr((s),(c))) ? (size_t)(strrchr((s),(c))-(s)) : -1) > >Note that these are *not* safe macros since the `s' argument may be >evaluated three times and the `c' argument twice. They also do twice as much work, and would be confusing to anyone who expects those names to have the V7/BSD semantics. Wouldn't it be simpler to just use strchr and strrchr, which should be present in any modern system? Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint