This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug! when a function is the parameter of another function.




  Do you get correct results if you do this as follows?

#include <stdio.h>

void func1(void)
{
    printf("hello world\n");
}

void func2(void (*f)())
{
    f();
}

int main(void)
{
    func2(&func1);
    return 1;
}

  Also, I never use the '&' operator on functions ... just the function 
name.  I'm not sure which is standard, but both seem to work on this example 
(probably because there is no way to pass a function by value, it is always 
passed by reference).



From: "Peng-Sheng Chen" <pschen@puma.cs.nthu.edu.tw>
>If I write a C program which include a function is the parameter of
>another function, gcc will produce wrong assembly-code.


-tim


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]