lkml.org 
[lkml]   [1998]   [May]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 'C' Operators precedence

On Wed, 20 May 1998, Hartmut Niemann wrote:

> >WRONG. See ANSI C standard section 6.3.2.2 Function Calls: `The
> >expression that denotes the called function shall have type pointer to
> >function...', or Example 2 following section 6.7.1, which explicitly
> >shows that (*funcp)() is equivalent to funcp(), when funcp is declared
> >as int (*funcp)(void).
>
> Somewhere I read something like:
> C operator precedence, practical subset:
> (1) * and / precede + and -
> (2) everything else will be grouped by ( and )
>
> ('Practical C programming' from O'Reilly??)
>
> You don't assume that everybody understands
> funcp()
> as an abbreviation of
> (* funcp)()
> do you? At least the second one makes clear that funcp is not a function
> defined.
> So even if ANSI, POSIX and the gcc and it's manual agree, that the first
> (funcp() without parentheses) is legal, does it make sense to use this
> form?
>
> Hartmut

Surely it is more sensible. I don't read the standards or anything, but
from my humble understanding you can use the name of a declared function
as a pointer, so it makes sense that you should be able to call a function
using a pointer using exactly the same syntax.

int fruit;

void lemons(void)
{
++fruit;
}

int main()
{
void (*lemons_alias)(void);

/* using function name as pointer */

lemons_alias = lemons;

/* using function pointer as name */

lemons_alias();

return 0;
}

Just my 2 cents ...

P.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu

\
 
 \ /
  Last update: 2005-03-22 13:42    [W:0.030 / U:0.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site