Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!julius.cs.uiuc.edu!rpi!bu.edu!inmet!draper From: draper@inmet.inmet.com Newsgroups: comp.lang.c Subject: Re: Trouble with curses Message-ID: <20900013@inmet> Date: 29 Oct 90 22:02:00 GMT References: <173826@<1990Oct27> Lines: 44 Nf-ID: #R:<1990Oct27:173826:inmet:20900013:000:1564 Nf-From: inmet.inmet.com!draper Oct 29 17:02:00 1990 I received mail today saying that I had correctly identified the line of code in the curses problem that was causing the problem, but I had missed the problem altogehter. These were my comments on the following line: switch(tolower(getch())) { /* I would watch out on the above line of code. tolower is a */ /* macro that might have undesriable effects should the user */ /* enter a character that is already in lower case. A good */ /* thing to do would be check if the char was an upper case */ /* using "isupper" before calling "tolower". */ It was brought to my attemntion that the macro 'tolower' might expand out so that getch() is called twice. That would cause the error that was described in the posting. I could not beleive that I missed that. I plead guilty to not thinking of that, BUT I DID NOT miss it. On the system I am using, Sun4 , in the file ctype.h , the macro tolower is defined as follows: #define tolower(c) ((c)-'A'+'a') I would like to thank the indivdual who sent mail to me on this (sorry I mistakenly deleted your mail before I saved it to a file) . It is a situation that I haven't ran across myself. Moral of the story: Always make sure you know, or at least think you know, how your macros will expand. When in doubt run the code throught cpp and look at the expansions. - Dave Internet: draper@inmet.inmet.com UUNET: uunet!inmet!draper ----- Intermetrics Microsystems Software, Incorporated 733 Concord Avenue Cambridge, MA 02138 (617) 661-0072 x4573