ARDUINO MEGA Functions Miscellaneous
From ROBOTC API Guide
(→memcmp) |
|||
| (6 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | <yambe:breadcrumb>ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb> | + | {{DISPLAYTITLE:2560 (MEGA) Miscellaneous Functions}} |
| + | <yambe:breadcrumb self="2560 (MEGA) Miscellaneous">ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb> | ||
<br /> | <br /> | ||
| Line 91: | Line 92: | ||
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | class="functionType"| <span class="bigKeywordBI">intrinsic short </span><span class="bigKeywordB">memcmp</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">void </span><span class="bigCodeBasic">&pToBuffer</span><span class="bigCodePunc">, </span><span class="bigKeywordBI"> | + | | class="functionType"| <span class="bigKeywordBI">intrinsic short </span><span class="bigKeywordB">memcmp</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">void </span><span class="bigCodeBasic">&pToBuffer</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">void </span><span class="bigCodeBasic">&pFromBuffer</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const short </span><span class="bigCodeBasic">nNumbOfBytes</span><span class="bigCodePunc">)</span> |
|- | |- | ||
| − | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) | + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Compares the first set bytes of the block of memory referenced by "pToBuffer" to the first number of bytes referenced by "pFromBuffer". The function will return zero if they all match or a value different from zero representing which is greater if they do not. |
|- | |- | ||
| | | | ||
| Line 102: | Line 103: | ||
|- | |- | ||
| style="border-style: solid; border-width: 1px 0px 1px 0px"|''pToBuffer'' | | style="border-style: solid; border-width: 1px 0px 1px 0px"|''pToBuffer'' | ||
| − | | style="border-style: solid; border-width: 1px 0px 1px 0px"|buffer to | + | | style="border-style: solid; border-width: 1px 0px 1px 0px"|First buffer to compare. |
| style="border-style: solid; border-width: 1px 0px 1px 0px"|[[Data_Types#dataType_void|void]] | | style="border-style: solid; border-width: 1px 0px 1px 0px"|[[Data_Types#dataType_void|void]] | ||
|- | |- | ||
| style="border-style: solid; border-width: 0px 0px 1px 0px"|''pFromBuffer'' | | style="border-style: solid; border-width: 0px 0px 1px 0px"|''pFromBuffer'' | ||
| − | | style="border-style: solid; border-width: 0px 0px 1px 0px"|buffer to | + | | style="border-style: solid; border-width: 0px 0px 1px 0px"|Second buffer to compare. |
| style="border-style: solid; border-width: 0px 0px 1px 0px"|[[Data_Types#dataType_void|void]] | | style="border-style: solid; border-width: 0px 0px 1px 0px"|[[Data_Types#dataType_void|void]] | ||
|- | |- | ||
| style="border-style: solid; border-width: 0px 0px 0px 0px"|''nNumbOfBytes'' | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''nNumbOfBytes'' | ||
| − | | style="border-style: solid; border-width: 0px 0px 0px 0px"| | + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|Number of bytes to compare |
| style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_short|short]] | | style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_short|short]] | ||
|- | |- | ||
| Line 129: | Line 130: | ||
<br /> | <br /> | ||
| − | == | + | == memmove == |
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB"> | + | | class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">memmove</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">void </span><span class="bigCodeBasic">&pToBuffer</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const void </span><span class="bigCodeBasic">&pFromBuffer</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const short </span><span class="bigCodeBasic">nNumbOfBytes</span><span class="bigCodePunc">)</span> |
|- | |- | ||
| − | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) | + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Function copies characters from <span class="codeBasic">pFromBuffer</span> to <span class="codeBasic">pToBuffer</span>. <span class="codeBasic">nBytesToCopy</span> is the number of bytes to copy. Identical to the function found in conventional C 'string.h' library. |
| + | |||
| + | The advantage of "memmove" is that the buffers can overlap in memory space - the "memcpy" function they cannot overlap. | ||
|- | |- | ||
| | | | ||
| Line 143: | Line 146: | ||
|- | |- | ||
| style="border-style: solid; border-width: 1px 0px 1px 0px"|''pToBuffer'' | | style="border-style: solid; border-width: 1px 0px 1px 0px"|''pToBuffer'' | ||
| − | | style="border-style: solid; border-width: 1px 0px 1px 0px"|buffer to | + | | style="border-style: solid; border-width: 1px 0px 1px 0px"|buffer to copy to |
| style="border-style: solid; border-width: 1px 0px 1px 0px"|[[Data_Types#dataType_void|void]] | | style="border-style: solid; border-width: 1px 0px 1px 0px"|[[Data_Types#dataType_void|void]] | ||
|- | |- | ||
| − | | style="border-style: solid; border-width: 0px 0px 1px 0px"|'' | + | | style="border-style: solid; border-width: 0px 0px 1px 0px"|''pFromBuffer'' |
| − | | style="border-style: solid; border-width: 0px 0px 1px 0px"| | + | | style="border-style: solid; border-width: 0px 0px 1px 0px"|buffer to copy from |
| − | | style="border-style: solid; border-width: 0px 0px 1px 0px"|[[Data_Types# | + | | style="border-style: solid; border-width: 0px 0px 1px 0px"|[[Data_Types#dataType_void|void]] |
|- | |- | ||
| style="border-style: solid; border-width: 0px 0px 0px 0px"|''nNumbOfBytes'' | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''nNumbOfBytes'' | ||
| − | | style="border-style: solid; border-width: 0px 0px 0px 0px"|number of bytes to | + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|number of bytes to copy |
| style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_short|short]] | | style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_short|short]] | ||
|- | |- | ||
| Line 160: | Line 163: | ||
|- | |- | ||
|<syntaxhighlight lang="robotc"> | |<syntaxhighlight lang="robotc"> | ||
| − | + | task main() | |
| − | + | { | |
| − | + | string source = "ROBOTC is cool!...."; // create string variable 'source' and set it to "ROBOTC is cool!...." | |
| − | + | string destination = ""; // create string variable 'destination' and set it equal to "" | |
| + | int length = 15; // create int variable 'length' and set it equal to 15 | ||
| + | |||
| + | memmove(destination, source, length); // copy 'length' number of bytes (15) from 'source' to 'destination' | ||
| + | |||
| + | while(true); // infinite loop to keep the debugger alive to see output | ||
| + | // after running: | ||
| + | // source = "ROBOTC is cool!...." | ||
| + | // destination = "ROBOTC is cool!" | ||
| + | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
Latest revision as of 13:52, 11 May 2012
ARDUINO → Functions and Variables → 2560 (MEGA) Miscellaneous
|
| |||||||
memcpy
| void memcpy(void &pToBuffer, const void &pFromBuffer, const short nNumbOfBytes) | ||||||||||||
| (void) Function copies characters from pFromBuffer to pToBuffer. nBytesToCopy is the number of bytes to copy. Identical to the function found in conventional C 'string.h' library. | ||||||||||||
| ||||||||||||
|
memset
| void memset(void &pToBuffer, const short nValue, const short nNumbOfBytes) | ||||||||||||
| (void) Sets a block of memory at pToBuffer to the value nValue. nNumbOfBytes is the number of bytes to set. This is a useful function for initializing the value of an array to all zeros. Identical to the function found in conventional C 'string.h' library. | ||||||||||||
| ||||||||||||
|
memcmp
| intrinsic short memcmp(void &pToBuffer, void &pFromBuffer, const short nNumbOfBytes) | ||||||||||||
| (void) Compares the first set bytes of the block of memory referenced by "pToBuffer" to the first number of bytes referenced by "pFromBuffer". The function will return zero if they all match or a value different from zero representing which is greater if they do not. | ||||||||||||
| ||||||||||||
|
memmove
| void memmove(void &pToBuffer, const void &pFromBuffer, const short nNumbOfBytes) | ||||||||||||
| (void) Function copies characters from pFromBuffer to pToBuffer. nBytesToCopy is the number of bytes to copy. Identical to the function found in conventional C 'string.h' library.
The advantage of "memmove" is that the buffers can overlap in memory space - the "memcpy" function they cannot overlap. | ||||||||||||
| ||||||||||||
|