Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

uni code

 
Babar Saeed
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i compile this code i receive an error message
char c = '\u000a';
even when i comment this line like this
// char c = '\u000a';
still there is an error.
it does not accept comment on this line
why is it so ? and what's the error in this statement?
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow.. weird. You're right! Even if its in a comment, it won't accept it. Must be a bug. I did b and it worked. Hmmm...
char c = '\u000b';
-Dale
------------------
What's this H2SO4 doing in my fridge?? ( thud )
[This message has been edited by Dale DeMott (edited July 11, 2001).]
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope - no bug. The sequence that you used is the unicode equivalent of a linefeed. Since the codes are converted to their values BEFORE the syntax is compiled, that unicode was replaced with the linefeed, creating a file that looked like:
// char c = '
';
The first line is commented out, but not the second line, and that is invalid syntax, therefore the error.

From the Java Language Specification:

The character and string escape sequences allow for the representation of some nongraphic characters as well as the single quote, double quote, and backslash
characters in character literals (�3.10.4) and string literals (�3.10.5).
EscapeSequence:
\ b = /* \u0008: backspace BS */
\ t = /* \u0009: horizontal tab HT */
\ n = /* \u000a: linefeed LF */
\ f = /* \u000c: form feed FF */
\ r = /* \u000d: carriage return CR */
\ " = /* \u0022: double quote " */
\ ' = /* \u0027: single quote ' */
\ \ = /* \u005c: backslash \ */

Therefore if you WANT to put a linefeed in your char you must use the supplied substitute instead.
So you should have coded:
// char c = '\n';
[This message has been edited by Cindy Glass (edited July 11, 2001).]
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Babar
I think it may have somehting to with the fact that one of the fiorst things the compiler does is transform all of the unicode escapes in the file. Thats why this line of code is valid

it becomes

I think what is happening is that it transforming the \u000a into a line feed (that's what 000a is) and then complains that you have a line feed in the middle of your declaration. To the compiler it probably looks like this

Dales' example worked because 000b is a tab.
hope this helped
Dave

Cindy types faster than I do She also probably didn't have to go to the jls to make sure she was right

[This message has been edited by Dave Vick (edited July 11, 2001).]
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OH yes I did .
 
Babar Saeed
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx a lot David
and Cindy Glass
now i'm clear about the code
//char c = '\u000a';
Again thanx a lot for ur cooperation.
 
Babar Saeed
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx a lot David
and Cindy Glass
now i'm clear about the code
//char c = '\u000a';
Again thanx a lot for ur cooperation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic