Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bahlquist

macrumors member
Original poster
Oct 6, 2010
41
0
This program:

Code:
#include <curses.h>

main()
{
  cbreak();
  noecho();
  printw("Hello, world!");
  getch();
}

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.
 
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.

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
 
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().
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.