# Character literals and uint8

This topic is 4848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

If I create a uint8, and try to assign a character literal, I get an error. For example:
uint8 fill;
fill = '0';
I get the following error: "Error : Expected expression value" This isn't a critical problem (I'm using setfill, i.e. "cout << std.setfill('0')"), since I can substitute the ASCII equivalent in hex, decimal, whatever. I'm just curious if it should be allowed.

##### Share on other sites
It's funny when people mistake questions about AngelScript syntax for questions about C++. [wink] (As a moderator I can see deleted posts.)

Single character literals are not implemented in the AngelScript syntax yet. I haven't decided if I will do so either.

Currently I suggest that you expose a function like 'uint8 ascii(string&in)' that returns the ascii code for the first character in the string, or use numeric constants.

##### Share on other sites
Quote:
 Original post by WitchLordIt's funny when people mistake questions about AngelScript syntax for questions about C++. [wink] (As a moderator I can see deleted posts.)

I don't understand exactly what you mean [looksaround]. Granted, AngelScript is not C++, and with such close syntax, I guess I went with the same syntax.

Quote:
 Original post by WitchLordSingle character literals are not implemented in the AngelScript syntax yet. I haven't decided if I will do so either.

I'm no compiler expert, and what you have so far is great. There's no great need for them (we can make do with numeric constants), but I wasn't sure if it was available. There's no mention in the ScriptWriter's manual, but I was hoping... [grin]

##### Share on other sites
I'm sorry about the confusion, I should have explained better. Just before my answer to your question someone else answered. That person mistook your question for being about C++, and answered it as such. However, he (or she) realized his own mistake and deleted the post before anyone could see it, except for those of us who are moderators. [wink]

Character literals wouldn't be difficult to implement, I just can't decide wether I want them or not. I've come to know that in C/C++ character literals are really interpreted by the preprocessor, so the underlying compiler really don't understand them. AngelScript could support them in the same way, and in fact, with Deyja's preprocessor it already does.

##### Share on other sites
Indeed it does. I ran across this same problem some time back, and asked WL about it. After a bit of research, I discovered that in C++ the preprocessor handles it, so I added it to mine. It does it in the simplest way imaginable. When it detects a ' character, it assumes the next character is the one to encode, and the one after it is another '. It does absolutly no error checking, and if you do something like 'lotsofcharacters' you will get some rather hard to decode error in angelscript. It does support escapes, but only newline, carriage return, and tab.

1. 1
Rutin
47
2. 2
3. 3
4. 4
5. 5

• 10
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633405
• Total Posts
3011680
• ### Who's Online (See full list)

There are no registered users currently online

×