Re: Question on strncmp / strnicmp use



On Jan 16, 7:34 pm, Barry Schwarz <schwa...@xxxxxxxx> wrote:
On Fri, 16 Jan 2009 08:13:59 -0800 (PST), vipps...@xxxxxxxxx wrote:

Here's what I have in mind:

strlen can't be less than O(n) (optimizations that, say, check 4
elements at once are still O(n))
mycomparison can't be less than O(n).

Using just mycomparison instead of strlen + mycomparison is one less O
(n) function called, so in that way, I'm correct.
You mention increment of pointers and comparison, but those operations
are O(1).

All that is not supported by the standard which doesn't even mention
the concept of efficiency/time of operation, but I hope you can see
what I'm trying to say.

As an abstract theoretical exercise, maybe you are right.   But I
think your frame of reference may be restricted by your experience
with a limited number of systems.

There are machines where strlen can be implemented as a single
instruction.  Under the as if rule, the compiler need not even
generate a function call.

The same is true regarding strncmp.  Furthermore, these machines can
allow both strings to populate cache.

Standards seem to have a life of 10+ years while hardware development
proceeds at a much faster rate.  Since the manufacturer of one such
machine is on the standards committee (and made these optimizations
primarily to support C and C++), this may one reason the standard
omits such considerations.

Thanks, with your explanation now I see the point Ben Bacarisse made,
and I agree with both.
.



Relevant Pages

  • Re: new IL: C (sort of...).
    ... and the frontend compiler needs to be able ... Having very limited pointers is a fact of life in a VM language though, ... vague claims about Pascal's pointer support. ... That is pretty normal for standards (the ...
    (comp.lang.misc)
  • Re: Proper way to do casts while avoiding aliasing issues
    ... The classic example these days, for machines with "weird" pointers, ... decided to give you "sub-word" data types to hold characters. ... So history repeats -- or as Mark Twain was supposed to have said, ...
    (comp.lang.c)
  • Re: Accelerated legacy code
    ... lots of code which doesn't fit new standards, ... And even if the facts supported the idea of the necessity of keeping Win98 machines around, ... Windows Server 2008, Linux, or MacOS. ...
    (comp.lang.cobol)
  • Re: [fbsd_questions] "i386" fbsd_platform vs "amd64" fbsd_platform, on "intel_64_architecture" cpu
    ... now, i change hardware so frequently, it is better to include probes for everything. ... when i am using 32_bit pointers. ... "killer_app", then i need two machines, ... i want to get started on seeing what the compiler produces, so, ...
    (freebsd-questions)
  • Re: The destruction of the C99 standard
    ... In the end we had to perform several rounds of code-size optimisations ... shame if the standards encourage laziness in this sort of area. ... little demand for a feature, but that the feature is impossible or ... variety of machines, many of them *much* smaller than 32K. ...
    (comp.std.c)