Thread: Typedefing function pointers

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    24

    Typedefing function pointers

    Code:
    int func(int a,int b);
    {
      return(a+b);
    }
    
    
    typedef int (*AddFp)(int,int);
    
    
    int main()
    {
      AddFp addf;
      addf=&func;
      return 0;
    }
    In linux, this tiny piece of code gives me the following error-
    Code:
    sample.c:3:1: error: expected identifier or ‘(’ before ‘{’ token
    Can someone please tell me why I'm getting this error?
    Thanks in advance!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > int func(int a,int b);
    Error message is for line 3, try looking at line 1.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    The extra semi-colon?

    The one at the end of the line "int func(int a,int b);"
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Aug 2012
    Posts
    24
    oh..so careless of me! Thanks guys!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. different ways of typedefing
    By dayalsoap in forum C Programming
    Replies: 8
    Last Post: 09-14-2010, 05:35 AM
  2. size of struct with pointers and function pointers
    By sdsjohnny in forum C Programming
    Replies: 3
    Last Post: 07-02-2010, 05:19 AM
  3. Storing function pointers in generic pointers
    By Boxknife in forum C Programming
    Replies: 6
    Last Post: 08-01-2009, 01:33 PM
  4. Variable pointers and function pointers
    By Luciferek in forum C++ Programming
    Replies: 11
    Last Post: 08-02-2008, 02:04 AM
  5. Quick Q - Typedefing integers
    By Verdagon in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2005, 08:28 PM