two arguments own parenthesis?.!¿

This is a discussion on two arguments own parenthesis?.!¿ within the C++ Programming forums, part of the General Programming Boards category; typedef int ( *ffp )( float ); //why are there two? test() { ffp fp = (ffp)myex; } can this ...

  1. #1
    Shadow12345
    Guest

    two arguments own parenthesis?.!¿

    typedef int ( *ffp )( float ); //why are there two?
    test()
    {
    ffp fp = (ffp)myex;
    }

    can this same code be written as:
    typedef int (*ffp, float);
    test()
    {
    ffp fp = (ffp)myex;
    }

    ????

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I don't think so. It looks like your code is casting a value twice (using old C-style casts) to get the correct type.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    typedef int ( *ffp )( float ); //why are there two?

    this is making a type called 'ffp' which is a pointer to a function that has one argument that is of type float, and returns an int.

    the use of the two sets of parenthesis make it easier to read, and it's the proper way of declaring a pointer to a function

    hope that helps
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >the use of the two sets of parenthesis make it easier to read
    That too, but the biggest reason is that without the parens it's no longer a function pointer. Take these two declarations for example:

    int ( *fp ) ( float );
    int *fp ( float );

    The only difference is the lack of parens, but the declarations are completely different. The first declares fp, a pointer to a function that takes a float as an argument and returns int. The second declares a function called fp that takes a float as its argument and returns an int pointer. The second is like saying:

    int *( fp ) ( float );

    Which doesn't work since the * binds to the return type instead of the function identifier.

    Just elaborating on your answer Uraldor.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 02:17 AM
  2. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 04:27 PM
  3. command line arguments
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 06-22-2008, 07:46 AM
  4. Replies: 10
    Last Post: 09-27-2005, 01:49 PM
  5. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 11:48 AM

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