SHORT VERSION:
//_LIT8(KCRLF, "\13\10"😉; //This does not work
//_LIT8(KCRLF, "\0x0d\0x0a"😉; //This does not work
_LIT8(KCRLF, "\r\n"😉; //This works
eightBitDesc.Append(KCRLF);
What is wrong with the broken approaches and is the approach that works safe on both the emulator and target hardware (MS compiler and GCC)?
------------------------------------------------------------
LONG VERSION:
Many internet protocols require the use of a carriage return and line feed in various places. (i.e. HTTP, MIME, etc.) This corresponds to ascii characters 13 and 10 respectively.
My problem is that I am having difficulty inserting ascii character values into an 8 bit descriptor. I also worry that the escape sequence "\n" which resolves to a carriage return using Microsoft's compiler will not do so when gcc compiles my code for the target Series 60 hardware.
According to "Thinking in C++" escape sequences are compiler specific and consequently could vary between Microsoft's and GNU's compiler. (Borland's compiler is also relevant if your using their IDE.) Considering that "\n" is known to be defined differently on Unix and Windows I am particularly concerned. Especially since gcc has a Unix herritage.
********
The following abreviated tables may be helpful to the reader:
ASCII Table:
Char. Dec. hex Comments
-------------------------------------------
LF 10 0A ^J Line Feed
CR 13 0D ^M Carriage Return
Relevant escape sequences from MSDN Documentation
Char. ASCII Escape
Dec. Sequence
----------------------------------
NL(LF) 10 \n
CR 13 \r
********
It may also be useful to list the definition of the _LIT8 macro:
#define _LIT8(name, s) const static TLitC8<sizeof(s)> name={sizeof(s)-1,s}
********
I have tried the following code within the Visual Studio debugger and examined the contents of the descriptor with each variation.
//_LIT8(KCRLF, "\13\10"😉; //This does not work
//_LIT8(KCRLF, "\0x0d\0x0a"😉; //This does not work
_LIT8(KCRLF, "\r\n"😉; //This works
eightBitDesc.Append(KCRLF);
Only the use of "\r\n" within _LIT8() results in the ascii characters 13 and 10 being inserted into the descriptor. The other two attempts using "\13\10" and "\0x0d\0x0a" do not.
------------------------------------------------------------
QUESTIONS SUMMARY:
My questions are:
1) How do I insert ascii characters into an 8 bit descriptor using the ascii values?
2) Does the "\n" escape sequence resolve to ascii character 10 using any compiler relevant to the Symbian platform?
3) Is there a better way to approach this problem that I am overlooking? (i.e. Is CRLF already defined by some system wide constant?)
------------------------------------------------------------
THANKS:
Thank you for your time and effort spent reading this posting. Any answers will be appreciated.
Sincerely,
James Carpenter
Email: [email protected]
AOL IM: nawkboyrules