Re: max vs &max as argument
- From: Jordan Abel <random@xxxxxxxxxxxxx>
- Date: 2 Nov 2006 19:18:23 GMT
(wow - for once something that would actually have been on-topic for
c.l.c, not posted there. what a reversal)
2006-11-02 <y93u01hach3.fsf@xxxxxxxxxxxxxxxxxxxx>,
Allan Adler wrote:
This is about using GCC under RedHat 7.1 Linux. I thought I should post it
here since it probably doesn't reflect either general behavior of C or of GCC
but depends on the Linux implementation. This is gcc 2.96, which I'm told
officially doesn't exist.
I wrote a routine super_assoc(int n, int * L, int (*g)(int,int))
which is supposed to take a list L of length >= n and to compute g
of the first n elts of L iteratively, i.e. if n=1 then it just returns L[0],
if n=2 it returns g(L[0],L[1]) and if n>2 it returns
g(super_assoc(n-1,L,g),L[n-1]). For example, it lets me escalate a binary
routine to compute the max of two elements into a routine that computes the
max of a list of elements.
What I'm puzzled about is the fact that the program seems to return a
correct result when I call it incorrectly as, e.g. assoc_op(3,L,max)
instead of as assoc_op(3,L,&max), which also returns the correct result.
Any idea why this might be the case? I'll post the code if necessary,
but this program is so simple it doesn't seem necessary.
You can use a bare name of a function as a function pointer. That is in
the standard. So no "depends on the linux implementation" - it is in the
standard, using the function name without & for that always has worked
and always will work everywhere for as long as C has/will existed.
.
- References:
- max vs &max as argument
- From: Allan Adler
- max vs &max as argument
- Prev by Date: max vs &max as argument
- Next by Date: Re: max vs &max as argument
- Previous by thread: max vs &max as argument
- Next by thread: Re: max vs &max as argument
- Index(es):
Relevant Pages
|
|