Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Bus Error with getch?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bus Error with getch?



On Dec 1, 2006, at 8:49 PM, Andre-John Mas wrote:

On 1-Dec-06, at 23:06 , Eric Albert wrote:

On Dec 1, 2006, at 6:42 PM, Andre-John Mas wrote:

I am getting a Bus Error with this very simple application, on my MacBook Pro:

int main ( int argc, char *argv )
{
    int c = getch();
    //printf( "%c", c );
}

I compiling it with the following command line:

cc getch.c -lcurses

Is this me or libcurses in cause?

main is declared as returning an int and you aren't returning anything. Try adding 'return 0;'.


I'd suggest compiling your code with warnings on, ideally via - Wall. That'll catch things like this.

Changing the code to:

#include <curses.h>

int main ( int argc, char **argv )
{
    getch();
    return 0;
}

and compiling with -Wall:

cc getch2.c -Wall -lcurses

gives me no warnings and yet it still crashes. Commenting out getch () the program no longer crashes.
Just curious as to whether this works for you? I am trying this on MacOS X 10.4.8

A bit of Googling shows that you have to call initscr() before using any curses APIs. That fixes this.


Hope this helps,
Eric

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Bus Error with getch? (From: Andre-John Mas <email@hidden>)
 >Re: Bus Error with getch? (From: Eric Albert <email@hidden>)
 >Re: Bus Error with getch? (From: Andre-John Mas <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.