>> In article <>
>> Richard Harter <> wrote:
>>>You can have intrinsics and still have a standard library. Some
>>>languages do. Regardless, if something is an intrinsic you don't
>>>need a library to get it.
>On 27 Aug 2008 19:34:20 GMT, Chris Torek posted:
>> That last seems like an odd statement to me ...
In article <>
Ron Ford <> wrote:
>Thanks, Chris, there is definitely a useful contrast here between C and the
>common extension that is fortran. I'm reconfiguring my mingw C capability
>but think I can call qsort from another syntax. Since C is likely to be
>under the hood of many syntaxes that can call C, I wanted to see how to do
>this thing that I think is important.
I have no idea what you mean by this, so I will ignore it.
>Calling it from a place without every C99 guarantee is a bit of a trick:
>
>%- > Is qsort an intrinsic for C?
>%-
>%- Yes, but despite the name it isn't guaranteed to
>%- implement quicksort.
>%-
>%- The advantage is that it can sort an array of any kind
>%- of data structure given a pointer to the array (usual
>%- for C), the length, the length of each array element
>%- (which must be in contiguous storage), and a comparison
>%- function. The comparison function is given pointers to
>%- two elements and returns a positive, zero, or negative
>%- value if the first is greater then, equal to, or less
>%- than the second. With the appropriate compare function
>%- the array can be an array of pointers, or structures
>%- containing pointers.
>%-
>%- To do that in Fortran 2003 might also require a routine
>%- to copy such array elements.
>
>Is Glen (quoted) correct?
I assume by "(quoted)" you refer to the statements marked "%-"
here.
The first statement (that it is an "intrinsic") is correct *if*
"intrinsic" means, as I would assume in this case, "the compiler
is allowed to recognize the name, and make assumptions about it,
e.g., replacing the call with inline code so that no library routine
is called". The part of the statement that says it is not guaranteed
to implement (Hoare's) Quick Sort is true unconditionally.
(If "intrinsic" means "something that need not use normal function
call syntax" -- as is true of Fortran's power operator, for instance,
even though A**B may call a library routine -- then this part of the
statement is false. There may be several other things people mean
by the word "intrinsic", depending on what language(s) they have
used. For instance, SNOBOL's string operations and success/fail
behavior could be considered its "intrinsics". Under most of these
meanings, I believe C's qsort() would not be an "intrinsic".)
The second part of the statement, about the advantage, is true.
(But there is a constraint on the comparison function: it must be
consistent. That is, the result of (*compar)(A,B) must stay the
same from call to call when A and B indicate the same element,
even if that element moves within the array.)
The third part of the statement, concerning Fortran 2003: I have
no idea. The last time I used Fortran was pre-1990.
[Regarding substituting for "library"-section functions, i.e., stuff
described in section 7 of the C Standard:]
>I guess the notion of keyword is less sacred in the non C world.
>They say you just change what the linker finds first.
Be careful when talking with "them".
As was the case with Fortran through the 1980s at least, this only
*sometimes* works. For instance, with gcc:
#include <stdio.h>
int main(void) {
printf("hello world\n");
return 0;
}
does not always call the library printf() routine. (Sometimes it
calls the library puts() routine, depending on optimization options.)
Similarly, "calls" to sqrt() or memcpy() can be replaced, under
some conditions, with inline instructions. So attempts to subvert
the library need not work, and -- unless you know what you are
doing, or verify quite carefully -- some *do* not work, on real
systems.
That said, I do not know of any C implementations that modify calls
to qsort(). Of course, this does not guarantee that none exist.
(Among other things, to cross comp.lang.c threads a bit, I have
never seen or used a [full] C99 implementation. Perhaps one of
those -- several are rumored to exist -- might substitute some
qsort() calls, for instance.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out)
http://web.torek.net/torek/index.html