Closed
Bug 57087
Opened 24 years ago
Closed 24 years ago
NS_LITERAL_STRING doesn't allow literal concats inside the operation on Windows
Categories
(Core :: XPCOM, defect, P3)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
mozilla0.8
People
(Reporter: dmosedale, Assigned: scc)
Details
Attachments
(1 file)
I often use NS_LITERAL_STRING on long strings that need to be broken across
multiple lines. So I tend to use constructs that split literal strings across
lines, like so:
NS_LITERAL_STRING("the quick brown fox jumped over the "
"lazy goat")
This currently causes the windows compiler to barf.
In nsAReadableString.h, around line 1534, we see:
#ifdef HAVE_CPP_2BYTE_WCHAR_T
#define NS_LITERAL_STRING(s) nsLiteralString(L##s,
(sizeof(L##s)/sizeof(wchar_t))-1)
#define NS_NAMED_LITERAL_STRING(n,s) nsLiteralString n(L##s,
(sizeof(L##s)/sizeof(wchar_t))-1)
#else
My suspicion is that replacing the 4 instances of |s| with |(s)| would fix this
problem.
Assignee | ||
Comment 1•24 years ago
|
||
The main problem I have with this is that in practice
L"hello"
defines a wide string, but
L("hello")
turns out to be a function call to an undefined function. Checking the
standard, I find (my normal quotes added to show what parts they labeled as
literals)
2.13.4 String literals [lex.string]
string literal:
|"| s-char-sequence[opt] |"|
|L"| s-char-sequence[opt] |"|
This language will definitely be interpreted by a compiler writer as implying
that |L"| is a single token which cannot be interrupted by whitespace or parens.
It is this that makes me have to say |L##s| in the macro, which leads not only
to this problem, but to the bad interaction with other macros, e.g.,
#define MY_STRING "hello"
// ...
... NS_LITERAL_STRING(MY_STRING) ...
At least that problem can be solved (thanks timeless for the first use of this) with
#define MY_STRING NS_LITERAL_STRING("hello")
Now maybe, if you were willing to double wrap your string parts, we could come
up with something. Since
L"xxx" L"yyy"
must be equivalent to
L"xxxyyy"
maybe we can make a pair of macros that work together ... one to conditionally
provide the |L|, the other to make the object declaration and size calculation.
This would make you put something like this in your code
NS_MULTILINE_LITERAL_STRING( NS_L("the first ...")
NS_L("...")
NS_L("...") )
Does that work for you? What do you think would be appropriate names? for this
new family of macros?
Status: NEW → ASSIGNED
Reporter | ||
Comment 2•24 years ago
|
||
Sure, that seems reasonable. And the names you suggest seem as good as any.
Assignee | ||
Updated•24 years ago
|
Component: XPCOM → String
Target Milestone: --- → mozilla0.8
Assignee | ||
Comment 3•24 years ago
|
||
Assignee | ||
Updated•24 years ago
|
Comment 4•24 years ago
|
||
Looks okay to me. [r|sr]=waterson, pick one.
Reporter | ||
Comment 5•24 years ago
|
||
Assignee | ||
Comment 6•24 years ago
|
||
patch checked in
Updated•4 years ago
|
Component: String → XPCOM
You need to log in
before you can comment on or make changes to this bug.
Description
•