Re: return the start of a substring in a string in c




"Ben Bacarisse" <ben.usenet@xxxxxxxxx> wrote in message
Why do say integers usually count things? Don't you ever calculate
things with integers? I used to work on projects (cryptography stuff)
where calculating was more common than counting and ints were
always too short. Counting is usually done with integers, but you
can't turn that round the other way.

As Flash says, we've been through all this before. I even pulled up some Java stats that showed pretty clearly that there were about as many indexed array accesses as integer operations in a sample of Java programs. I couldn't find a similar study for C, though I didn't try too hard, but there is no reason to suppose that C programs are radically different from Java ones.

Computers spend most of their cycles moving data from one place to another, and most integers are used to count things in the computer's memory. That's not every cycle, of course, nor is every single integer a count of something - cryptography is an obvious exception, as are intermediate results in frequency transforms, or pixel colours. The last leads us to another issue, in a typical image function

void setpixel(long *img, int width, int height, int x, int y, long val)
{
assert(x >= 0 && x < width);
assert*y >= 0 && y < height);
img[y*width + x] = height;
}

How many integers do we have? You could say width * height, plus a few, or you could say six, of which two are pixel values and four intermediates in array calculations. I'm counting it as six, which isn't the only answer justifiable, but makes sense in the context of how best to define the types in a high-level language.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

.



Relevant Pages

  • Re: counting down or up is faster
    ... int main ... assuming everything as same except the for loops and if variable i 's ... usage has no problem with up or down counting which is faster? ... Pay particular attention to the sections titled "Bottlenecks", ...
    (comp.lang.c)
  • Re: return an int from a function
    ... int func{ ... //process the num, counting the loop ...
    (comp.lang.c)
  • Re: Integer Types
    ... I think you mean "int", ... Since most of the time we are counting things in the computer's memory, ... technical reasons the integer registers are usually the same width as the ...
    (comp.lang.c)
  • Re: algorithm to identify number from 0-16384 having at most 4 1s in its binary number
    ... It's probably worth using the well-known algorithm for counting ... the number of bits set in a word (and shortcircuiting the thing ... int main ... Prev by Date: ...
    (sci.math)
  • Re: factorial of very big number like 4096
    ... Richard Heathfield wrote: ... Well, I started off by calculating 4096!, and storing that result in a file. ... int main ... printf(" {\n"); ...
    (comp.lang.c)