Re: max vs &max as argument



(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.
.



Relevant Pages

  • Re: max vs &max as argument
    ... here since it probably doesn't reflect either general behavior of C or of GCC ... I wrote a routine super_assoc) ... constant pointer to the array data. ... tauno voipio iki fi ...
    (comp.os.linux.misc)
  • Re: Use MMX or SSE for Apple II
    ... inlined assembly instructions and so the entire routine will have to be ... Shawn is correct since I have read newsgroups at comp.lang.asm.x86 1-2 ... I highly doubt that inline assembly is disabled in the GNU Compiler ... All that gcc does anyway is to forward the stuff to ...
    (comp.sys.apple2)
  • max vs &max as argument
    ... This is about using GCC under RedHat 7.1 Linux. ... I wrote a routine super_assoc(int n, int * L, int (*g)) ...
    (comp.os.linux.misc)
  • Re: assembly optimization on ARM /(armv5tde xscale).
    ... Sylvain wrote: ... > Can anyone check the routine to see if there are blatant mistakes, ... > This is actually inline ARM assembly for GCC. ...
    (comp.sys.arm)
  • Re: Requesting advice how to clean up C code for validating string represents integer
    ... GNU C is the C-like language accepted by gcc. ... violate the C standard. ... that you get the GNU C version of each library rather than the ANSI ...
    (comp.lang.c)