Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does "typedef void (*wskfun)(const string)" mean?

What does "typedef void (*wskfun)(const string) mean, and why it is necessery to use it in creating structure if we want to attach function to the single node of node list?

typedef void (*wskfun)(const string);

struct w2k {
    w2k* next; 
    w2k* prev;

    string nazwa;

    wskfun fun;
};

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This typedef

typedef void (*wskfun)(const string);

declares a pointer to a function that has the return void and one argument of the type const string.

Without the typedef the structure will look the following way

struct w2k {
    w2k* next; 
    w2k* prev;

    string nazwa;

    void ( *fun )( const string );
};

Instead of the typedef of a function pointer the code will be more readable if you will declare a typedef for the function type like for example

typedef void wskfun(const string);

struct w2k {
    w2k* next; 
    w2k* prev;

    string nazwa;

    wskfun *fun;
};

If it is a C++ code then it is better to accept an object of the type std::string by reference. That is the typedef will look like

typedef void wskfun(const string &);

If it is a C code then it seems the name string in turn denotes a typedef name like

typedef char *string;

In this case using the specification const string does not make a great sense. It will be better to write

typedef void wskfun(const char *);

because const string means char * const instead of const char *.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading