Thread: function as a type or object

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    35

    function as a type or object

    I was wondering, how is this done: when you pass the name of a function to a macro and it will call that function when it needs to, like this line of code:
    GTK_SIGNAL_FUCN(eventFunction);
    How does this work/how can I do this myself?
    you make me rery ascared

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Maybe something like this.
    Code:
    #include <stdio.h>
    
    #define A(x)   (x)()
    #define B(x,y) (x)(y)
    
    void foo(void)          { puts("Hello world");         }
    void bar(void)          { puts("Goodbye cruel world"); }
    void baz(const char *s) { puts(s);                     }
    
    int main(void)
    {
       A(foo);
       A(bar);
       B(baz, "Hello again");
       return 0;
    }
    
    /* my output
    Hello world
    Goodbye cruel world
    Hello again
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    35
    Thank you!
    you make me rery ascared

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: function as a type or object

    Originally posted by techrolla
    I was wondering, how is this done: when you pass the name of a function to a macro and it will call that function when it needs to, like this line of code:
    GTK_SIGNAL_FUCN(eventFunction);
    How does this work/how can I do this myself?
    If it is a macro, you should be able to find it in the relevant .h file and see for yourself.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: Re: function as a type or object

    Originally posted by Hammer
    If it is a macro, you should be able to find it in the relevant .h file and see for yourself.
    My compiler doesn't seem to have "relevant.h"...

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

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Perhaps he meant revelation.h, it's where you'll find the answers to all of C's dark mysteries
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM