View unanswered posts | View active topics It is currently Mon Sep 21, 2020 12:33 am

Reply to topic  [ 3 posts ] 
RobotC integer constants 
Author Message

Joined: Sat Jun 09, 2007 8:41 am
Posts: 7
Post RobotC integer constants
In RobotC what is the data type of an integer constant?

If I try something like:
long k = 32767;
then the value of k is 32767

but, if I try:
long k = 32768;
then the value of k is -32768

and if I try
long k = 32768L;
I get a compiler error.

Thu Jun 28, 2007 9:29 am

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
ROBOTC support 8, 16 and 32 bit integers. 8-bit were just recently added and works best in version 1.07.

Data types are char (8), byte (8), int (16), short (16), and long (32).

'int' are 16-bits and not the 32-bit size found on larger systems. Many embeeded CPUs use 16-bit values for the 'int' variables.

The "L" abbreviation is not used on specifying constants. This is a minor implementation oversight. Instead, the compiler looks at whether the numeric constant is integer or floating point. If integer, then looks at how many bits are required to store the value to determine whether it is byte, short or long.

"long k = 32768" works fine for me. You do need to be careful about compiler code optimization. If you have code optimization enabled, and never rewrite 'k', then all references to 'k' will likely get replaced with the constant '32768' and 'k' will not be referenced within your code; unfortunately it turned out to be too hard to then delete the memory allocation for 'k' so it is still left around.

You may also want to try "const long k = 32768;". This extension to the C language is supported by ROBOTC -- its actually something in C++ and not in C. No memory will be allocated and 'k' will be a true constant.

If you still think there's a problem, post a short but complete and runnable program and I will re-pexamine.

Thu Jun 28, 2007 5:17 pm

Joined: Sat Jun 09, 2007 8:41 am
Posts: 7
Post RobotC integer constants
Hi Dick

Thanks for the information on RobotC data types. I didn't actualy have a program, I was trying to learn how to program using RobotC. So I was trying things out, like data types.

This was my program:

task main
long k = 32768;

When I run the program and I look at the Global Variables window. I see the variable k and the value -32768. I also experimented with using k in an expression, and based on the results, I think the variable k was 32 bits, and the value of k was -32768, not +32768.

I think I saw that you posted a new version of RobotC, so I'll try this in the new version.


Fri Jun 29, 2007 7:49 am
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests

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 post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.