[try Beta version]
Not logged in

 
Escape sequences

Aug 18, 2010 at 6:23pm
I'm currently writing an instant messaging program and I need a way to specify what kind of data is being sent. I decided to use escape sequences:
\c - Command (sent to other clients, e.g. to tell them to connect a new user)
\a - Audio (to be streamed to the user)
\i - Image (to be shown on the GUI)
\s - String (to be printed as a message)
\v - Video (to be streamed to the user)

Upon compilation, gcc warns me that \c, for example, is not recognised as an escape character. I'm wondering if this really matters. Will there be any bad side-effects to using escape sequences and, if so, what alternative is there?
Aug 18, 2010 at 6:28pm
If you want to include a literal "\" in a string, you need to escape it, since it's a special character (namely, the escape character).

So for example:

string str = "This \\ is okay!";
Aug 18, 2010 at 6:31pm
I know, I'm asking if using escapes that aren't defined is acceptable. \a is defined as the 'alert' sound and '\v' is defined as vertical tab. What I'm asking is whether using \c, \i and \s (which aren't defined as escape sequences) will have any side-effects.
Aug 18, 2010 at 6:59pm
It seems that the '\' is ignored, so '\s' == 's'.
Why not use normal chars?
Aug 18, 2010 at 7:06pm
It's an instant messaging program. If I used normal characters like 'c' for commands, then the message "cool" would be parsed as a command.
Last edited on Aug 18, 2010 at 7:07pm
Aug 18, 2010 at 7:41pm
Just prefix all types of messages with a byte that indicates the message type. This can be a character, but it doesn't have to be.
If someone actually sends a string "cool", it would be sent as "scool", so there is no ambiguity.
Aug 18, 2010 at 8:08pm
That doesn't work, though. How can the program know what characters are included by the user? I'm not writing a language parser... That's why I used escapes. If the user types "\a" I'll see it as "\\a" so it won't matter.

Edit: Wait, never mind. I think you're right. The client knows what data it's sending before sending it, so the [hypothetical] command "ool" which would be sent as "cool" would be different from the string "cool" which would be sent as "scool". Ok, thanks.
Last edited on Aug 18, 2010 at 8:10pm
Topic archived. No new replies allowed.