468,531 Members | 1,721 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,531 developers. It's quick & easy.

why is the backslash-space combo a escape sequence 040

The printf function returns "warning: unknown escape sequence: \040"
for a backslash-space combination. If the ascii decimal number for
space is 32 and the backslash is 92, why this particular number 040?
Is it a decimal number from the ASCII code chart? (compiling using gcc
on SunOS 5.8, Sparc, Ultra-80)
Just curious. Thanks.

Sep 23 '07 #1
5 14399
In article <11**********************@r29g2000hsg.googlegroups .com>,
vlsidesign <fo*****@gmail.comwrote:
>The printf function returns "warning: unknown escape sequence: \040"
for a backslash-space combination. If the ascii decimal number for
space is 32 and the backslash is 92, why this particular number 040?
Is it a decimal number from the ASCII code chart?
It is an octal number from the ASCII code chart. 4*8^1 + 0*8^0 = 32 (decimal)
--
Programming is what happens while you're busy making other plans.
Sep 23 '07 #2
vlsidesign <fo*****@gmail.comwrites:
The printf function returns "warning: unknown escape sequence: \040"
for a backslash-space combination. If the ascii decimal number for
space is 32 and the backslash is 92, why this particular number 040?
Is it a decimal number from the ASCII code chart? (compiling using gcc
on SunOS 5.8, Sparc, Ultra-80)
I doubt that the printf function itself is returning this message; the
only escape sequences printf knows about are the ones introduced by
the '%' character. Probably you're using "\040" in a string literal,
and your compiler is complaining about it; the fact that you're using
that string literal in a printf call is irrelevant. Try using the
string literal in another context, and you should get the same message:

char *s = "your literal";

In a string or character literal, the sequence \040 denotes the octal
value of the character (your C textbook should explain this). 040
octal is 32 decimal, which happens to be the ASCII code for the space
character (though C doesn't require ASCII).

It would have been very helpful if you had posted the actual
copy-and-pasted code that caused the problem.

Here's a small C translation unit:

char *backslash_space = "\ ";
char *backslash_bang = "\!";

and gcc's output:

c.c:1:25: warning: unknown escape sequence: '\040'
c.c:2:25: warning: unknown escape sequence '\!'

Presumably gcc shows the space character as 040 to avoid the visual
ambiguity of printing the actual space character.

The C standard doesn't specify the form of diagnostic messages;
compilers other than gcc will produce different messages. For
example, here's the output of another compiler:

"c.c", line 1: warning: dubious escape: \
"c.c", line 2: warning: dubious escape: \!

and another:

"c.c", line 1.25: 1506-235 (W) Incorrect escape sequence \ . \ ignored.
"c.c", line 2.25: 1506-235 (W) Incorrect escape sequence \!. \ ignored.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 23 '07 #3
On Sun, 23 Sep 2007 07:05:37 +0000, vlsidesign wrote:
The printf function returns "warning: unknown escape sequence: \040"
for a backslash-space combination. If the ascii decimal number for
space is 32 and the backslash is 92, why this particular number 040?
Is it a decimal number from the ASCII code chart?
040 is octal for 32.
Backslashes in string literals are always taken as escape
sequences. If you want to use one, try "\\".

--
Army1987 (Replace "NOSPAM" with "email")
A hamburger is better than nothing.
Nothing is better than eternal happiness.
Therefore, a hamburger is better than eternal happiness.

Sep 23 '07 #4
vlsidesign wrote:
>
The printf function returns "warning: unknown escape sequence:
\040" for a backslash-space combination. If the ascii decimal
number for space is 32 and the backslash is 92, why this
particular number 040? Is it a decimal number from the ASCII code
chart? (compiling using gcc on SunOS 5.8, Sparc, Ultra-80)
It's the octal code for a space, as indicated by the leading 0.
The 'escape space' combination is only valid at the termination of
a C source line, and is effectively absorbed.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Sep 23 '07 #5
CBFalconer <cb********@yahoo.comwrites:
vlsidesign wrote:
>The printf function returns "warning: unknown escape sequence:
\040" for a backslash-space combination. If the ascii decimal
number for space is 32 and the backslash is 92, why this
particular number 040? Is it a decimal number from the ASCII code
chart? (compiling using gcc on SunOS 5.8, Sparc, Ultra-80)

It's the octal code for a space, as indicated by the leading 0.
The 'escape space' combination is only valid at the termination of
a C source line, and is effectively absorbed.
No, a backslash followed by a space is not legal at the end of a line.
A backslash can be used to join two logical lines but the backslash
must *immediately* precede the new-line character. See C99 5.1.1.2p2.

Some compilers may allow spaces after a backslash as an extension.
It's a reasonable one, since trailing whitespace is typically
invisible. Variations in text file formats may also affect this.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 23 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Ladvánszky Károly | last post: by
3 posts views Thread by Sathyaish | last post: by
6 posts views Thread by John Salerno | last post: by
3 posts views Thread by Stef Mientki | last post: by
2 posts views Thread by Tobiah | last post: by
4 posts views Thread by Razzbar | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.