Menu

#40 #define doesn't work properly when //anycomment follows

open
nobody
None
5
2004-12-10
2004-12-10
Anonymous
No

If I have, a #define that looks like :
#define MY_CONST //anycomment
then the constant name is "MY_CONST //anycomment",
which is probably a very bad idea.

A simple workaround follows :
class BooleanEvaluator {

[...]

private String trimSpacesAndTabs(String
symbol) {
int index_of_space = symbol.indexOf
(" ");
while (index_of_space != -1) symbol
= symbol.substring(0, index_of_space);
int index_of_tab = symbol.indexOf
('\t');
while (index_of_tab != -1) symbol =
symbol.substring(0, index_of_tab);
return symbol;
}

/**
* Defines a symbol, thus making its value true
* when the symbol is used in further
expressions.
*/
public void define(String symbol) {
symbol = trimSpacesAndTabs
(symbol);
symbols.put(symbol, symbol);
}

/**
* Defines a symbol, thus making its value false
* when the symbol is used in further
expressions.
*/
public void undefine(String symbol) {
symbol = trimSpacesAndTabs
(symbol);
symbols.remove(symbol);
}

Discussion