(uninteresting) parsing and virtual functions

This is a discussion on (uninteresting) parsing and virtual functions within the A Brief History of Cprogramming.com forums, part of the Community Boards category; So far work on the source file lexer has been proceeding nicely... Most of C is fairly straightfoward to parse. ...

  1. #1
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435

    (uninteresting) parsing and virtual functions

    So far work on the source file lexer has been proceeding nicely... Most of C is fairly straightfoward to parse. So I'm writing the name mangler, I'm just about done it... when I realize I've forgotten about function pointers. I'm not even sure I remember the correct syntax for using a function pointer, or an array of functions pointer... How should I test for a declaration of a function pointer? Where exactly do they go? You have variables, you have functions, you have pointers.. and you have function pointers. It's like a new category of thingies that doesn't exactly fit under any of the other category, and cannot be treated under any of the other rules. Damn. More work
    .sect signature

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    Function pointer:

    typedef void (fnptr*)(void);

    Array of functions, using that function pointer:

    //declare and define functions

    void f1 ( void ) {
    printf("Hello from 1");
    }

    void f2 ( void ) {
    printf("Hello from 2");
    }

    void f3 (void) {
    cout << "Hello from 3";
    }

    void f4 (void) {
    cout << "Hello from 4";
    }

    void f5 (void) {
    cout << "Hello from 5";
    }

    /* initialise the array of fn pointers */
    /* a pointer to a fn is just its name */

    fnptr array[5] = {
    f1, f2, f3, f4, f5
    };

    Main function using array:

    int main (void)
    {
    int i;
    for ( i = 0 ; i < 5 ; i++ ) {
    array[i]();
    }
    getch();
    return 0;
    }
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

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