I don’t know, I wanna talk. What variable types do you guys use and why?
There are no doubles in RobotC.
Use floats for any non-integer quantity. Use ints all other times.
oof, i thought there were doubles, must have been mistaken
The language allows the type, but it generates an informative warning. Here’s a short test program I just compiled:
task main()
{
float scaleFactor;
double scaleFactor2;
scaleFactor = 1.1;
scaleFactor2 = 1.2;
}
And here’s a screenshot of the warning generated:
this thread is sorta useless since there isn’t a whole lot anybody can do since doubles would shake things up (not really it’s just a data type that can hold more data)
Does RobotC support Long? It sucks when you are counting and suddenly you are an unexpectedly small or negative number.
Yes, the VEX Cortex does support longs. Though it should be noted that this is not unanimous across all RobotC platforms. Longs are used to support the internal timer architecture.
If you are interested in the capacilities of a platoform, you can take a look in the “LoadBuildOptions(Platform).h” file for all of the defines related to that platform. In the case of longs, you are looking for “useLongs”, which can be found on line 50:
#define useFloats // VEX_CORTEX
#define useLongs // VEX_CORTEX
#define useStackVariables // VEX_CORTEX
Using this, we can now quickly test the functionality on any platform by looking for a function that would only work if longs were enabled in the RobotCIntrinsics.c file based on the build options defined. An example of this is the function
randlong(void)
which is only enabled if
useLongs == true
as per the below code:
#if defined(bHasRandomFunctions)
intrinsic short rand(void) asm(opcdSystemFunctions, byte(sysFuncRandomWord), functionReturn);
intrinsic void srand(const short nSeedValue) asm(opcdSystemFunctions, byte(sysFuncSRandWord), variable(nSeedValue));
#if defined(useLongs)
intrinsic long randlong(void) asm(opcdSystemFunctions, byte(sysFuncRandomLong), functionReturn);
intrinsic void srand(const long nSeedValue) asm(opcdSystemFunctions, byte(sysFuncSRandLong), variableRefLong(nSeedValue));
#endif
#else
#define srand(seed) random[0] = seed
#define rand() random[0x7FFF]
#endif
Now we can test that in some code, an example is here:
long sizetest;
task main() {
sizetest = randlong();
writeDebugStreamLine("%d", sizetest);
}
and we could be fairly sure of our result if we encounter no errors.