If it is legal, should I call this always when exiting from ncurses? Or is it automatically called from What are the consequences of doing endwin()?delwin(stdscr)?
If it is legal, should I call this always when exiting from ncurses? Or is it automatically called from What are the consequences of doing endwin()?delwin(stdscr)?
That's multiple questions:
- If it is legal, should I call this always when exiting from ncurses?
- Or is it automatically called from endwin()?
- What are the consequences of doing delwin(stdscr)?
The first two are equivalent (it's not necessary in any implementation of curses, and not something that endwin does). Call that two questions, then. The first asks how delwin and endwin are related, and the other asks about specific behavior of delwin. The latter is interesting.
Actually it's probably implementation-dependent.
Limiting it to ncurses (per tag),
delwin calls_nc_freewin, which callsremove_window_from_screen, which makes a special check for each of curscr, newscr and stdscr (setting the value of those global variables to NULL if the window to be deleted happens to match, before deallocating their respective data).So it works for ncurses. I added the feature in December 1996:
+ modify _nc_freewin() to reset globals curscr/newscr/stdscr when
freeing the corresponding WINDOW (found using Purify).
Regarding portability:
There were two questions. The other regards endwin. That never deletes a window, because it is always possible to follow a call to endwin with a call to wrefresh. It's in the manual page:
Calling refresh(3x) or doupdate(3x) after a temporary escape causes the
program to resume visual mode.
However, if you did a delwin(stdscr) between the endwin() and wrefresh(stdscr) calls, ncurses would return an error for the latter. NetBSD (read the code to see that it will dereference a null pointer) and Solaris would both dump core.