functions calls Vs calls using function pointers

Andrew Haley aph@redhat.com
Thu May 25 15:51:00 GMT 2006


Digvijoy Chatterjee writes:
 > In 5/25/06, Andrew Haley <aph@redhat.com> wrote:
 > >
 > > You declare fp to be type void (*fptr) (int).
 > >
 > > Therefore if you call a function through fp, you have to pass an int.
 > > This is because of the type of variable fp, not because of A.
 > >
 > > You can easily demonstrate this by compiling:
 > >
 > > typedef void (*fptr) (int);
 > >
 > > int main()
 > > {
 > > fptr fp;
 > > fp();
 > > }
 > >
 > >  > I want the name of the function where the compiler while parsing a .c
 > >  > file associates a function pointer ,to the function which will be
 > >  > called at runtime.
 > >
 > > This never happens, and therefore I can't answer your question.
 > >
 > > Andrew.
 > >
 > Right ,
 > Which is the file then which has code , to compare the erroneous call
 > fp(); to its declaration as in the typedef 

Look at convert_arguments in c-typeck.c.

 > ?where does the compiler know fp() is a function call ?

	case CPP_OPEN_PAREN:
	  /* Function call.  */
	  c_parser_consume_token (parser);
	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
	    exprlist = NULL_TREE;
	  else
	    exprlist = c_parser_expr_list (parser, true);
	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
				     "expected %<)%>");
	  expr.value = build_function_call (expr.value, exprlist);
	  expr.original_code = ERROR_MARK;
	  break;


in c-parser.c.

Andrew.



More information about the Gcc-help mailing list