Possible Duplicate:
getch is deprecated
As title says, what are diffrences between those two methods? I’m new so I’m confused about the usage of them…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
At least in the implementations of which I’m aware, there’s no difference between the functions themselves. In fact, they’re generally just two different names for exactly the same function.
As to the reason for having two names: there really isn’t a very good one. Somebody at Microsoft apparently didn’t read the requirements of the standard very carefully, and made some rather…poor decisions based on misunderstanding it.
First,
getchisn’t declared in a standard header, so changing the name isn’t really necessary to start with1.Second, if they did need to change the name,_getchisn’t right anyway — the names reserved for the implementation start with an underscore (they got that much right) followed by either another underscore or a capital letter (which they got wrong). In other words, if they were going to change the name, it should have been either__getch, or_Getch, but at least as far as the standard cares,_getchis just as bad as plaingetch.As far as choosing between them goes: I’d just use
getchand be done with it. Using_getchactually makes your code (marginally) less portable — to do the same thing on most Unixesque systems, you use curses, which includes a function to do (mostly) the same job — and its name isgetch. As such, if you ever port your code, you’ll need to change the header(s) you include, but the namegetchis one of the few that will actually continue to work. If you’re doing much interactive I/O, you’ll probably have to rewrite quite a bit of other code though.1Well, it shouldn’t be anyway. Back in the 16-bit days, Microsoft’s linker had a little problem that you had to pass it an extra switch (
/noe) or any duplicate between names you defined, and names defined in a library you were linking would result in an error. So, back then you had to pass an extra switch to get code to link if it used the same name as anything in the library, not just a standard name. That’s pretty much ancient history though.