qsort 
August 27th, 2008, 02:05 AM
| | | qsort
Is qsort an intrinsic for C?
--
We must respect the other fellow's religion, but only in the sense and to
the extent that we respect his theory that his wife is beautiful and his
children smart. 5
H. L. Mencken | 
August 27th, 2008, 02:05 AM
| | | Re: qsort
Ron Ford wrote: Quote:
>
Is qsort an intrinsic for C?
| In hosted implementations, yes.
In freestanding implementations, no.
--
pete | 
August 27th, 2008, 02:05 AM
| | | Re: qsort
Ron Ford wrote: Quote:
>
Is qsort an intrinsic for C?
| qsort() is a function in C's Standard library, available
for use in all hosted implementations.
What's an "intrinsic?"
--
Eric Sosman esosman@ieee-dot-org.invalid | 
August 27th, 2008, 02:55 AM
| | | Re: qsort
On Tue, 26 Aug 2008 22:05:01 -0400, Eric Sosman posted: Quote:
Ron Ford wrote: Quote:
>>
>Is qsort an intrinsic for C?
| >
qsort() is a function in C's Standard library, available
for use in all hosted implementations.
>
What's an "intrinsic?"
| An intrinsic is something that comes with the food in a given syntax.
One of my intrinsics is that I like Hillary. Your mileage may vary.
I don't see qsort in K&R as I leaf through or in the index. Did I
photograph the wrong target when I thought to have read of qsort in K&R?
--
We are here and it is now. Further than that, all human knowledge is
moonshine. 3
H. L. Mencken | 
August 27th, 2008, 02:55 AM
| | | Re: qsort
On Aug 27, 5:47 am, Ron Ford <r...@example.invalidwrote: Quote:
On Tue, 26 Aug 2008 22:05:01 -0400, Eric Sosman posted:
>> Quote: Quote: |
Is qsort an intrinsic for C?
| | > Quote:
qsort() is a function in C's Standard library, available
for use in all hosted implementations.
| >>
An intrinsic is something that comes with the food in a given syntax.
| No it's not. Quote: |
One of my intrinsics is that I like Hillary. Your mileage may vary.
| Nonsense. Quote:
I don't see qsort in K&R as I leaf through or in the index. Did I
photograph the wrong target when I thought to have read of qsort in K&R?
| Photograph the wrong target? nonsense.
Which K&R? See Appendix B in K&R2. | 
August 27th, 2008, 03:45 AM
| | | Re: qsort
On Tue, 26 Aug 2008 22:05:01 -0400, Eric Sosman
<esosman@ieee-dot-org.invalidwrote: Quote:
>Ron Ford wrote: Quote:
>>
>Is qsort an intrinsic for C?
| >
qsort() is a function in C's Standard library, available
>for use in all hosted implementations.
>
What's an "intrinsic?"
| The term is used in Fortran and elsewhere; it means that the
function in question is an intrinsic part of the language in
contrast to being part of a library. I expect that you already
know this and that your question is rhetorical, but I thought it
worthy of answer anyway.
So, no, qsort is not an intrinsic; if it were you wouldn't need
to include stdlib.h nor would you need to link in the standard
library. Nor could you write your own qsort and use it, either
by omitting to include stdlib.h, or by simply replacing qsort in
the standard library.
Richard Harter, cri@tiac.net http://home.tiac.net/~cri, http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate. | 
August 27th, 2008, 04:25 AM
| | | Re: qsort
Ron Ford wrote: Quote:
>
The appendices in K&R are numbered.
>
| In hex maybe, but certainly not in decimal.
--
Ian Collins. | 
August 27th, 2008, 09:55 AM
| | | Re: qsort cri@tiac.net (Richard Harter) wrote: Quote:
On Tue, 26 Aug 2008 22:05:01 -0400, Eric Sosman
> Quote:
Ron Ford wrote: Quote:
>
Is qsort an intrinsic for C?
| | | Quote: >
The term is used in Fortran and elsewhere; it means that the
function in question is an intrinsic part of the language in
contrast to being part of a library.
| "A" library, or _the_ Standard Library? Languages which use the term
"intrinsic" usually don't distinguish between those two. C does. Quote:
So, no, qsort is not an intrinsic; if it were you wouldn't need
to include stdlib.h nor would you need to link in the standard
library.
| OTOH, qsort _is_ an intrinsic; if it weren't, you couldn't depend on it
existing in every conforming hosted implementation, on any system. Quote:
Nor could you write your own qsort and use it, either by omitting to
include stdlib.h, or by simply replacing qsort in the standard library.
| Guess what: despite the shoot-your-own-foot permission some
implementations may give you, the Standard doesn't guarantee that you
can do that, either.
Richard | 
August 27th, 2008, 12:15 PM
| | | Re: qsort
Richard Harter wrote: Quote:
On Tue, 26 Aug 2008 22:05:01 -0400, Eric Sosman
<esosman@ieee-dot-org.invalidwrote:
> Quote:
>Ron Ford wrote: Quote: |
>>Is qsort an intrinsic for C?
| > qsort() is a function in C's Standard library, available
>for use in all hosted implementations.
>>
> What's an "intrinsic?"
| >
The term is used in Fortran and elsewhere; [...]
| Yes, but this isn't comp.lang.fortran nor alt.st.elsewhere.
Also, you will find that the word "intrinsic" appears nowhere in
the C Standard, not even in non-normative text. I asked the
question to learn what "Ron Ford" thought the word meant, but
learned instead that "Ron Ford" is not worth paying any heed to.
--
Eric Sosman esosman@ieee-dot-org.invalid | 
August 27th, 2008, 04:25 PM
| | | Re: qsort
On Wed, 27 Aug 2008 09:51:24 GMT, rlb@hoekstra-uitgeverij.nl
(Richard Bos) wrote: Quote:
>cri@tiac.net (Richard Harter) wrote:
> Quote:
>On Tue, 26 Aug 2008 22:05:01 -0400, Eric Sosman
>> Quote:
>Ron Ford wrote:
>>
>Is qsort an intrinsic for C?
| | > Quote: >>
>The term is used in Fortran and elsewhere; it means that the
>function in question is an intrinsic part of the language in
>contrast to being part of a library.
| >
>"A" library, or _the_ Standard Library? Languages which use the term
>"intrinsic" usually don't distinguish between those two. C does.
| 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. Quote:
> Quote:
>So, no, qsort is not an intrinsic; if it were you wouldn't need
>to include stdlib.h nor would you need to link in the standard
>library.
| >
>OTOH, qsort _is_ an intrinsic; if it weren't, you couldn't depend on it
>existing in every conforming hosted implementation, on any system.
| And the fact that you can't depend on it existing in a
free-standing implementation shows that it is not an intrinsic;
if it were it would be there. Quote:
> Quote:
>Nor could you write your own qsort and use it, either by omitting to
>include stdlib.h, or by simply replacing qsort in the standard library.
| >
>Guess what: despite the shoot-your-own-foot permission some
>implementations may give you, the Standard doesn't guarantee that you
>can do that, either.
| Quite true, but beside the point. It is not even potentially
possible for intrinsics, since they aren't in libraries.
Richard Harter, cri@tiac.net http://home.tiac.net/~cri, http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate. | 
August 27th, 2008, 04:35 PM
| | | Re: qsort
On Wed, 27 Aug 2008 08:06:44 -0400, Eric Sosman
<esosman@ieee-dot-org.invalidwrote: Quote:
>Richard Harter wrote: Quote:
>On Tue, 26 Aug 2008 22:05:01 -0400, Eric Sosman
><esosman@ieee-dot-org.invalidwrote:
>> Quote:
>>Ron Ford wrote:
>>>Is qsort an intrinsic for C?
>> qsort() is a function in C's Standard library, available
>>for use in all hosted implementations.
>>>
>> What's an "intrinsic?"
| >>
>The term is used in Fortran and elsewhere; [...]
| >
Yes, but this isn't comp.lang.fortran nor alt.st.elsewhere.
>Also, you will find that the word "intrinsic" appears nowhere in
>the C Standard, not even in non-normative text.
| Quite true; still it isn't really necessary in comp.lang.c to
pretend that the rest of the world doesn't exist. If someone
asks if you can do closures in C, it's not much of an answer to
say that closures aren't defined in the standard. Quote:
>I asked the
>question to learn what "Ron Ford" thought the word meant, but
>learned instead that "Ron Ford" is not worth paying any heed to.
| That does seem to be the case.
Richard Harter, cri@tiac.net http://home.tiac.net/~cri, http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate. | 
August 27th, 2008, 07:45 PM
| | | Re: qsort
In article <48b57c3e.695125859@news.sbtc.net>
Richard Harter <cri@tiac.netwrote: Quote:
>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.
| That last seems like an odd statement to me, given that (e.g.) the
Fortran systems I have used have relied on a library (the one
automatically included by the "fort" or "f66" or "f77" or whatever
front-end command) to supply the code for most of the various
intrinsics.
(For that matter, the "standard C library" normally does not require
special link options when using the usual front-end commands. The
"-lm" flag to cc/gcc is the glaring annoying exception to this rule.) Quote: Quote:
>>Guess what: despite the shoot-your-own-foot permission some
>>implementations may give you, the Standard doesn't guarantee that you
>>can [use your own qsort], either.
| >
>Quite true, but beside the point. It is not even potentially
>possible for intrinsics, since they aren't in libraries.
| Again, in a number of those Fortran systems, it was easy to use
your own code for intrinsics, simply by adding the appropriate
object or library file to the link line (as the default Fortran
library was linked at the end). As in C, this was rarely if ever
officially supported, and sometimes the call you expected got
short-circuited, so (just as with C systems) you had to know what
you were doing. But it was more than just "potentially possible":
sometimes we even did it (to use special instructions, or work
around an implementation bug).
--
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 | 
September 3rd, 2008, 04:05 AM
| | | Re: qsort
On 27 Aug 2008 19:34:20 GMT, Chris Torek posted: Quote:
In article <48b57c3e.695125859@news.sbtc.net>
Richard Harter <cri@tiac.netwrote: Quote:
>>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.
| >
That last seems like an odd statement to me, given that (e.g.) the
Fortran systems I have used have relied on a library (the one
automatically included by the "fort" or "f66" or "f77" or whatever
front-end command) to supply the code for most of the various
intrinsics.
>
(For that matter, the "standard C library" normally does not require
special link options when using the usual front-end commands. The
"-lm" flag to cc/gcc is the glaring annoying exception to this rule.)
| 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.
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? Quote:
> Quote: Quote:
>>>Guess what: despite the shoot-your-own-foot permission some
>>>implementations may give you, the Standard doesn't guarantee that you
>>>can [use your own qsort], either.
| >>
>>Quite true, but beside the point. It is not even potentially
>>possible for intrinsics, since they aren't in libraries.
| >
Again, in a number of those Fortran systems, it was easy to use
your own code for intrinsics, simply by adding the appropriate
object or library file to the link line (as the default Fortran
library was linked at the end). As in C, this was rarely if ever
officially supported, and sometimes the call you expected got
short-circuited, so (just as with C systems) you had to know what
you were doing. But it was more than just "potentially possible":
sometimes we even did it (to use special instructions, or work
around an implementation bug).
| I guess the notion of keyword is less sacred in the non C world. They say
you just change what the linker finds first.
--
What men value in this world is not rights but privileges. 7
H. L. Mencken | 
September 5th, 2008, 05:35 AM
| | | Re: qsort
>In article <48b57c3e.695125859@news.sbtc.net> Quote: Quote:
>Richard Harter <cri@tiac.netwrote: Quote:
>>>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.
| | | Quote:
>On 27 Aug 2008 19:34:20 GMT, Chris Torek posted: Quote: |
>That last seems like an odd statement to me ...
| | In article <1kgfdwp8e1f62.dlg@example.invalid>
Ron Ford <ron@example.invalidwrote: Quote:
>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. Quote:
>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:] Quote:
>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 | 
September 6th, 2008, 05:15 PM
| | | Re: qsort
On 27 Aug 2008 19:34:20 GMT, Chris Torek <nospam@torek.net>
wrote: Quote:
>In article <48b57c3e.695125859@news.sbtc.net>
>Richard Harter <cri@tiac.netwrote: Quote:
>>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.
| >
>That last seems like an odd statement to me, given that (e.g.) the
>Fortran systems I have used have relied on a library (the one
>automatically included by the "fort" or "f66" or "f77" or whatever
>front-end command) to supply the code for most of the various
>intrinsics.
| My bad; I should have tried to be more precise about "needing a
library". I was being rather sloppy.
In languages such as C and fortran the language specification
does not include the process of generating an executable. The
entire process - compiling, linking, etc - is specific to the the
implementation. An implementation is free to do whatever is
convenient, e.g., put the object code for intrinsics in a library
or compile inline code for standard library routines.
What is at issue is the code itself. Code using intrinsics is,
so to speak, self contained; the language itself specifies the
interfaces for intrinsics. There is no need for any external
references.
In languages such as C code using standard libraries is, so to
speak, not self contained; it must make references to external
code (include files) that specify the interfaces. Again the fact
that many implementations let you omit include files is not to
the point.
So "need the library to get it" should read "need to reference
external code to get interface description". The issue at hand
hand is the meaning of intrinsics vs standard libraries in the
context of compute languages. Talking about actual libraries as
I did just confuses the matter. Quote:
>
>(For that matter, the "standard C library" normally does not require
>special link options when using the usual front-end commands. The
>"-lm" flag to cc/gcc is the glaring annoying exception to this rule.)
> Quote: Quote:
>>>Guess what: despite the shoot-your-own-foot permission some
>>>implementations may give you, the Standard doesn't guarantee that you
>>>can [use your own qsort], either.
| | | I let this slide; this is one for the language lawyers. Clearly
I can't use my own qsort if the standard qsort is being used
elsewhere. But it seems to me that it must be legal to write my
own qsort as a static function in a file. Quote: Quote:
>>
>>Quite true, but beside the point. It is not even potentially
>>possible for intrinsics, since they aren't in libraries.
| >
>Again, in a number of those Fortran systems, it was easy to use
>your own code for intrinsics, simply by adding the appropriate
>object or library file to the link line (as the default Fortran
>library was linked at the end). As in C, this was rarely if ever
>officially supported, and sometimes the call you expected got
>short-circuited, so (just as with C systems) you had to know what
>you were doing. But it was more than just "potentially possible":
>sometimes we even did it (to use special instructions, or work
>around an implementation bug).
| We did a lot of that sort of stuff in the old days. People still
do.
Richard Harter, cri@tiac.net http://home.tiac.net/~cri, http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate. | 
September 6th, 2008, 08:45 PM
| | | Re: qsort
In article <7f-dnZDfrPzK3ijVnZ2dnUVZ_hqdnZ2d@comcast.com>,
Eric Sosman <esosman@ieee-dot-org.invalidpouted:
.... Quote:
Yes, but this isn't comp.lang.fortran nor alt.st.elsewhere.
>Also, you will find that the word "intrinsic" appears nowhere in
>the C Standard, not even in non-normative text. I asked the
>question to learn what "Ron Ford" thought the word meant, but
>learned instead that "Ron Ford" is not worth paying any heed to.
| Just how old are you? 8? 10? 12?
Don't you think now might be a good time to do some growing up?
The nice thing about growing up is that you might be able to hold down a
job. Then, you might actually be able to afford a place of your own.
Then (and this is the good part), you won't have to worry anymore about
mommy taking away your computer privileges. | 
September 6th, 2008, 08:45 PM
| | | Re: qsort
In article <48b57e5d.695667718@news.sbtc.net>,
Richard Harter <cri@tiac.netwrote:
.... Quote:
>Quite true; still it isn't really necessary in comp.lang.c to
>pretend that the rest of the world doesn't exist. If someone
>asks if you can do closures in C, it's not much of an answer to
>say that closures aren't defined in the standard.
| It is the only acceptable answer here. | 
September 6th, 2008, 10:25 PM
| | | Re: qsort
On 6 Sep 2008 at 20:35, Kenny McCormack wrote: Quote:
Don't you think now might be a good time to do some growing up?
>
The nice thing about growing up is that you might be able to hold down
a job.
| If you believe his email address, Sossman is employed by Sun. I wonder
what they'd make to someone conducting a hate campaign against Jacob
Navia with their company's name stamped all over it. | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,989 network members.
|