Thread: (uninteresting) parsing and virtual functions

  1. #1
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001

    (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
    Plano, Texas, United States
    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++ ) {
    return 0;
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed