typedef a func

This is a discussion on typedef a func within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> typedef ( void ( )( int ) ) fptr; /* this doesn't work */ void f( int ...

  1. #1
    Registered User trekker's Avatar
    Join Date
    Mar 2002
    Posts
    46

    typedef a func

    Code:
    #include <stdio.h>
    
    typedef ( void (  )( int ) ) fptr; /* this doesn't work */
    
    void
    f( int n );
    
    void ( *foo( void ( func )( int ) ) )( int );
    /*void ( *foo( void ( func )( int ) ) )( int );*/
    
    int main( void )
    {
    	f( 3 );
    	
    	/*foo( &f );*/
    	foo( f );
    	
    	( foo( f ) )( 9 );
    	
    	return 0;
    }
    
    
    void
    f( int n )
    {
    	printf( "n = %d\n", n );
    	
    	return;
    }
    
    
    void ( *foo( void ( func )( int ) ) )( int )
    {
    	//( *func )( 6 );
    	func( 6 );
    	
    	return func;
    }
    
    /*void ( *foo( void ( func )( int ) ) )( int )
    {
    	func( 6 );
    	
    	return func;
    }*/
    as you can see i want to typedef fptr to be ptr to function taking
    one int argument and returning void.
    The rest of the code is just to give you clue of what i'm trying to do

    thanks,
    trk
    to boldy code where...

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > The rest of the code is just to give you
    > clue of what i'm trying to do

    Aside from the entries in the Obfuscated C Contest code, your code is some of the hardest to read stuff I've ever run across.

    What exactly is it you're trying to do?

    > void ( *foo( void ( func )( int ) ) )( int )
    > {

    This is supposed to be what exactly?

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    Code:
    typedef void (fptr)(int);
    
    fptr *fn_ptr;
    fn_ptr = my_fn;
    (*fn_ptr)(10);

  4. #4
    Sayeh
    Guest
    My preferred method (I find it the most legible):

    Code:
    typedef int (*MYFUNC)(char arg1,char arg2);
    It makes it very easy to use anywhere you might need to have a function pointer-- freely, or in a structure, etc. For example:

    Code:
    typedef struct nodeStruc
       {
       struct nodeStruc *next;
       long                     procHandle;
       MYFUNC               procPtr;
       GDHandle            myGDeviceH;
       }node;

  5. #5
    Registered User trekker's Avatar
    Join Date
    Mar 2002
    Posts
    46
    Originally posted by quzah
    >
    Aside from the entries in the Obfuscated C Contest code, your code is some of the hardest to read stuff I've ever run across.

    Quzah.
    well, sorry...it came up pretty ugly.

    it is supposed to be a ptr to function which takes as an argument another function and returning a function returning void and has an int argument.
    The function argument is a function taking an int arg
    and returning void.

    trk
    Last edited by trekker; 07-02-2002 at 05:18 AM.
    to boldy code where...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  3. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 08:22 AM
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 06:35 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

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