View unanswered posts | View active topics It is currently Wed Aug 27, 2014 1:50 pm






Reply to topic  [ 8 posts ] 
Sample Errata? 
Author Message
Rookie

Joined: Fri Oct 25, 2013 11:34 am
Posts: 8
Post Sample Errata?
Not sure if there is a gathering place for errata from the samples but we found a bug in the NXTFileIOTest.c sample as I started going through them with my son.

At approx line 56:
sString = "ABC" + index; // sString is declared as "String"

fails to compile : Can't assign to 'const' qualified variable. Expression '"ABC" + index' is type 'string'

Is there a C++ style operator overloading that enables '+' for concatenation of strings? It seems this should work from what I found here - http://carrot.whitman.edu/Robots/NXT/Strings.htmhy would this be an issue with the current 3.62 out of the box?

Also tried:
sString = "ABC";
sString += index; // ERROR: Code generation for an invalid string assignment.

It was OK with:
sString = "ABC";
sString = sString + index;

Of course the following works as well:
WriteString(hFileHandle, nIoResult, sString);

What is going on here? Also I could not find anything on the native String support in the docs that come with RObotC or online other than the whitman doc listed above. Where is it?


Mon Oct 28, 2013 8:07 am
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Sample Errata?
I think this is a known bug; there was a thread on this a while back. Should be fixed in 4.0.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Mon Oct 28, 2013 8:02 pm
Profile
Rookie

Joined: Fri Oct 25, 2013 11:34 am
Posts: 8
Post Re: Sample Errata?
OK Thanks Ernest - could you point me to the documentation on the native String support? Could not find it in the docs etc other than Whitman site.


Mon Oct 28, 2013 9:50 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Sample Errata?
You mean you don't get this?


Attachments:
Capture.JPG
Capture.JPG [ 41.56 KiB | Viewed 1542 times ]
Mon Oct 28, 2013 9:58 pm
Profile
Rookie

Joined: Fri Oct 25, 2013 11:34 am
Posts: 8
Post Re: Sample Errata?
I got that, but where is the description for the String data type, the operators, and extension to the language. Those are merely functions that operate on strings. Generally where is THE the language definition for RobotC? Not the function library but the language.


Mon Oct 28, 2013 10:07 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Sample Errata?
To be honest with you, I don't use the "string" data type in RobotC. I think it has a limit of storing only 19 characters. I am not 100% sure. I haven't played with string for a long time, but that was the impression I got when I played with it long time ago. It seems pretty useless to me. Since 3.x now supports pointers, I use char array (and char *) instead. Having said that, char array also has a limit of about 220 characters. I have already filed a bug against it because I ran into that limitation when writing a program that requires long strings.


Mon Oct 28, 2013 10:20 pm
Profile
Rookie

Joined: Fri Oct 25, 2013 11:34 am
Posts: 8
Post Re: Sample Errata?
Yes that is how it would be done in "real" C ;) Is it strict on data typing? For example if a function expects a "String" type can you pass it something declared "char *" - does RobotC allow "casting" etc?


Tue Oct 29, 2013 8:05 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Sample Errata?
TheKog wrote:
Yes that is how it would be done in "real" C ;) Is it strict on data typing? For example if a function expects a "String" type can you pass it something declared "char *" - does RobotC allow "casting" etc?

If you are talking about the supported string related functions such as strcpy, strcat ... etc, they supported both "string" and "char *" types. For example, take a look at the file c:\Program Files (x86)\Robomatter Inc\ROBOTC Development Environment\Includes\RobotCIntrinsics.c
Code:
///////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                "string" functions on byte arrays
//
///////////////////////////////////////////////////////////////////////////////////////////////////////

#if defined(hasStringSupport)

intrinsic void strcpy(char *pToBuffer, const char *pFromBuffer)
                      asm(opcdSystemFunctions,
                          byte(sysFuncStrCpy),
                          variableRefCharPtr(pToBuffer),
                          variableRefCharPtr(pFromBuffer));

intrinsic void strcpy(string &pToBuffer, const char *pFromBuffer)
                      asm(opcdSystemFunctions,
                          byte(sysFuncStrNCpy),
                          variableRefString(pToBuffer),
                          variableRefCharPtr(pFromBuffer),
                          constantValue(20));

intrinsic void strncpy(char *pToBuffer, const char *pFromBuffer, const short nMaxBufferSize)
                      asm(opcdSystemFunctions,
                          byte(sysFuncStrNCpy),
                          variableRefCharPtr(pToBuffer),
                          variableRefCharPtr(pFromBuffer),
                          variable(nMaxBufferSize));

intrinsic void strcat(string &sToString, const char *pFromBuffer)
                      asm(opcdSystemFunctions, byte(sysFuncStrNCat),
                            variableRefString(sToString),
                            variableRefCharPtr(pFromBuffer),
                            constantValue(20));   // 'string' variable is 20 bytes long

intrinsic void strcat(char *pToBuffer, const char *pFromBuffer)
                      asm(opcdSystemFunctions, byte(sysFuncStrCat),
                            variableRefCharPtr(pToBuffer),
                            variableRefCharPtr(pFromBuffer));

intrinsic void strncat(char *pToBuffer, const char *pFromBuffer, const short nMaxBufferSize)
                      asm(opcdSystemFunctions,
                          byte(sysFuncStrNCat),
                          variableRefCharPtr(pToBuffer),
                          variableRefCharPtr(pFromBuffer),
                          variable(nMaxBufferSize));

intrinsic void strcatSingleChar(char &pToBuffer, const char cSingleChar)
                      asm(opcdSystemFunctions, byte(sysFuncStrCatSingleChar),
                            variableRefRAM(pToBuffer),
                            variable(cSingleChar));

intrinsic void strncatSingleChar(char *pToBuffer, const char cSingleChar, const short nMaxBufferSize)
                      asm(opcdSystemFunctions,
                          byte(sysFuncStrNCatSingleChar),
                          variableRefCharPtr(pToBuffer),
                          variable(cSingleChar),
                          variable(nMaxBufferSize));

intrinsic short strcmp(const char *pString1, const char *pString2)
                      asm(opcdSystemFunctions, byte(sysFuncStrCmp),
                            variableRefCharPtr(pString1),
                            variableRefCharPtr(pString2),
                            functionReturn);

intrinsic short strncmp(const char *pString1, const char *pString2, const short nMaxBufferSize)
                      asm(opcdSystemFunctions, byte(sysFuncStrNCmp),
                            variableRefCharPtr(pString1),
                            variableRefCharPtr(pString2),
                            variable(nMaxBufferSize),
                            functionReturn);

intrinsic char strIndex(const string &sString, const short nIndex)
                      asm(opcdSystemFunctions,
                          byte(sysFuncStrIndex),
                          variableRefString(sString),
                          variable(nIndex),
                          functionReturn);


intrinsic void strTrim(string &sString)
                      asm(opcdSystemFunctions,
                          byte(sysFuncStrNTrim),
                          variableRefString(sString),
                                       byte(parmSourceConstant), byte(20), byte(0));

intrinsic void strTrim(char *pString)
                      asm(opcdSystemFunctions,
                          byte(sysFuncStrTrim),
                          variableRefCharPtr(pString));

intrinsic void strTrimN(char *pString, const int nMaxBufferSize)
                      asm(opcdSystemFunctions,
                          byte(sysFuncStrNTrim),
                          variableRefCharPtr(pString),
                                       variable(nMaxBufferSize));


#endif

If you are talking about your own functions, RobotC does do type checking, but it will do automatic type conversion in some cases. For example, try the following code:
Code:
void myFunc(string &myStr)
{
    nxtDisplayTextLine(0, "%s", myStr);
}

task main()
{
    char *textString = "Hello World!";
    myFunc(textString);
    while (true)
    {
        wait1Msec(100);
    }
}


Tue Oct 29, 2013 8:57 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 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.