Re: Why is that?
From: Thomas Matthews (Thomas_MatthewsSpitsOnSpamBots_at_sbcglobal.net)
Date: 08/19/04
- Next message: RCollins: "Re: How to know the memory pointed by a ptr is freed?"
- Previous message: Eric Sosman: "Re: macro containing include statement"
- In reply to: Profetas: "Why is that?"
- Next in thread: Dave Thompson: "Re: Why is that?"
- Reply: Dave Thompson: "Re: Why is that?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 19 Aug 2004 14:47:16 GMT
Profetas wrote:
> I know what is causing the problem, but I couldn't
> find out why.
>
> #define newline "\n"
> #define question_mark "\?"
> #define single_quotas "\'"
> #define double_quotas "\""
> #define form_feed "\f"
> #define horizontal_tab "\t"
> #define vertical_tab "\v"
> #define backslash "\\"
One of the main problems of the above macros is
that you are using strings instead of characters.
If I have:
const char statement[] = "Hello\t\"World?\"";
And I want to search for a "question_mark",
I would naturally want to use:
char * posn;
posn = strchr(statement, question_mark);
Which will not work because strchr() requires
a single char as the second parameter. Also,
this one will be hard to find:
posn = strchr(question_mark, statement);
In the above line, the first parameter has the
correct type, but wrong logic.
Also, please check your spelling. Note that
in English, "quota" and "quote" are two different
words. A quota is a limit. One could have a
single quota. There could also be double quotas,
which means having two limits; which is far from
the symbol (").
At some point, macros lead more to obfuscating
a program than to readablility.
If you want to keep down this path, may I also
suggest these macros:
#define begin {
#define end }
#ifndef and
#define and &&
#endif
#ifndef or
#define or ||
#endif
#ifndef not
#define not !
#endif
#define ever 1
#define forever 1
while (forever)
begin
if (a and b)
begin
continue;
end
else
begin
break;
end
end
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
- Next message: RCollins: "Re: How to know the memory pointed by a ptr is freed?"
- Previous message: Eric Sosman: "Re: macro containing include statement"
- In reply to: Profetas: "Why is that?"
- Next in thread: Dave Thompson: "Re: Why is that?"
- Reply: Dave Thompson: "Re: Why is that?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|