This is the mail archive of the
libc-alpha@sourceware.cygnus.com
mailing list for the glibc project.
Re: pure string functions
>>>>> Andi Kleen writes:
Andi> Andreas Jaeger <aj@suse.de> writes:
>>
>> Some of common examples of pure functions are @code{strlen} or @code{memcmp}.
>> Interesting non-pure functions are functions with infinite loops or those
>> depending on volatile memory or other system resource, that may change between
>> two consetuctive calls (such as @code{feof} in multithreding environment).
Andi> So you are sure gcc correctly handles things like this in all cases with
Andi> pure strlen:
According to the documentation: Yes. ;-)
Andi> func()
Andi> {
Andi> char bla[10] = "blub";
Andi> int a,b;
Andi> a = strlen(bla);
Andi> // do something with a
Andi> func2(bla);
Andi> b = strlen(bla);
Andi> // do something with b
Andi> }
Andi> func2(char *bla)
Andi> {
Andi> bla[1] = 0;
Andi> }
Andi> ?
Andi> My understanding of pure functions was always that they are only
Andi> allowed to depend on argument values, but not on values pointers
Andi> point to.
That's a const function - a pure function is allowed to read memory -
but is not allowed to change memory!
Andreas
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.rhein-neckar.de