Typedefing function pointers

This is a discussion on Typedefing function pointers within the C Programming forums, part of the General Programming Boards category; Code: int func(int a,int b); { return(a+b); } typedef int (*AddFp)(int,int); int main() { AddFp addf; addf=&func; return 0; } ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,853
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21