CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How do you typecast char to int?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pop



Joined: 18 Sep 2004
Posts: 22

View user's profile Send private message

How do you typecast char to int?
PostPosted: Sat Sep 18, 2004 12:21 pm     Reply with quote

How do you typecast char to int? I am trying to convert any ascii character (e.g. letters, symbols, numbers etc.) to its integer equivalent, so that I can do some bit-masking operations. For example, I would like to convert letter 'z' to it's ascii integer equivalent of 122.

I know that in c++, this is easily done by something like the following:

int temp;
char myChar='z';

temp=(int) myChar;

However, CCS complains with following error: "A numeric expression must appear here".

My compiler version is 3.112.

Thanks
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sat Sep 18, 2004 1:26 pm     Reply with quote

That ought to work. I don't know why you are getting an error.
_________________
The search for better is endless. Instead simply find very good and get the job done.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Sep 18, 2004 1:28 pm     Reply with quote

To me your example code looks OK. I compiled it in PCH v3.187 and it compiles fine.

The only reasons I can think of for it not working with you are:
1) Your v3.112 compiler is very old and it may be a bug in this version.
2) The bug reporting system of the CCS compiler is lousy. Often another bug in the previous line is causing the compiler to go crazy. Check for missing ';' etc in the preceding line.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sat Sep 18, 2004 1:35 pm     Reply with quote

Just so you know, char and int are the same in CCS. Not true with all compilers but for CCS they are the same. You shouldn't need to convert them at all when using CCS.
pop



Joined: 18 Sep 2004
Posts: 22

View user's profile Send private message

PostPosted: Sat Sep 18, 2004 2:20 pm     Reply with quote

I've tried your suggestions, but I still receive the same compiler error.
I have also tried to directly bit-mask a char with an int (e.g. following Mark's recommendation), but that just produced the same compiler error as before.

I guess I'll just have to re-design my code around this problem, but it's good to know that the code is syntactically correct and works on other versions of ccs compilers.

Thanks for the swift help.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sat Sep 18, 2004 5:07 pm     Reply with quote

Maybe you should post a small test program that demonstrates the problem.
pop



Joined: 18 Sep 2004
Posts: 22

View user's profile Send private message

PostPosted: Sun Sep 19, 2004 6:06 pm     Reply with quote

It seems like it was a bad build.

I deleted all the project files, re-created the project, compiled and it worked like a charm. Very Happy

Thanks.
Guest








PostPosted: Mon Sep 20, 2004 2:14 pm     Reply with quote

frankly, I ran into a few problems like this:

A good running code won't compile under the same build CCS compiler.

All I do is to delete everything, except the .c .h files, and recreate the project, and everything works fine after that.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group