Bus error while running program that uses curses.h

Discussion in 'Mac Programming' started by bahlquist, Oct 8, 2010.

  1. bahlquist macrumors member

    Oct 6, 2010
    This program:

    #include <curses.h>
      printw("Hello, world!");
    produces a bus error when run. This is curious, because I am not aware of any pointers being dereferenced here. I'm running this from unix on 10.5.
  2. ulbador macrumors 68000


    Feb 11, 2010
    You have to call initscr() before you call any curses functions. Otherwise curses doesn't know the terminal type and anything about stdout/err/etc
  3. bahlquist thread starter macrumors member

    Oct 6, 2010
  4. ulbador macrumors 68000


    Feb 11, 2010
    Make sure you are a good little programmer and call endwin() at the end of your program too. Weird and odd things can happen to your terminal if your program exits and curses hasn't fully disconnected itself (though you probably wouldn't see these artifacts on this small of a program)

    That's why if you've ever used many curses or ncurses programs and you hit CTRL-C, the terminal stays weird colors or acts funny. The programmer didn't trap that signal and call endwin() before the program terminated.

    And with what you have there, the printw might not visibly print anything until you call the refresh() function. Printw prints to a hidden window which is not updated to the main screen until you call refresh().

Share This Page