Question

I'm making an ncurses application, and I've come accross something that's puzzling.

If you have a struct with a member named "refresh" that is a function pointer, and you call that function later, you will get the following compile-time error:

main.c:20:10: error: ‘Point’ has no member named ‘wrefresh’
     point.refresh();

Here's a little test you can try to compile:

#include <ncurses.h>

typedef struct PointStruct Point;

void Point_refresh() {

}

struct PointStruct {
    int x;
    int y;
    void (*refresh)();
};

int main() {
    Point point;
    point.x = 0;
    point.y = 0;
    point.refresh = &Point_refresh;
    point.refresh();
}

That will give you the error mentioned above. However, if you take out the first line that includes ncurses, it will compile with no issues.

What is the reason that this does not work with ncurses, and is there a way around it? It's not really a big deal, just a slight annoyance that I have to rename that member.

Was it helpful?

Solution

Because refresh() is a "pseudo-function" #defined by curses as a macro for wrefresh(win), so the preprocessor is going to replace all occurrences of that word in your source. There's no sensible way round it other to #undef it, and always use wrefresh() instead.

OTHER TIPS

Replace:

 point.refresh();

With:

(point.refresh)();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top