Trouble with curses
draper at inmet.inmet.com
draper at inmet.inmet.com
Tue Oct 30 09:02:00 AEST 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 at inmet.inmet.com
UUNET: uunet!inmet!draper
-----
Intermetrics Microsystems Software, Incorporated
733 Concord Avenue Cambridge, MA 02138
(617) 661-0072 x4573
More information about the Comp.lang.c
mailing list