Correct Usage Of CLEAR_BUFFER
klmyers
Posts: 6
I have used on a number of jobs a queuing routine that places commands in a char array. I have code that checks the length of the q and if it equals the MAX_LENGTH ARRAY of that variable declared size (for any reason), I clear it. Would a CLEAR_BUFFER on that variable name remove all that is in there??? or just assign that variable="" (2 double quotes) work. What is the correct syntax to use? Thanks in advance
0
Comments
If you have a variable defined as CHAR cBuffer[1024] then,
CLEAR_BUFFER cBuffer
cBuffer = ?? (single quotes)
cBuffer = ?? (double quotes)
SET_LENGTH_ARRAY(cBuffer,0)
SET_LENGTH_STRING(cBuffer,0)
will all yield the same result and none of the above options will alter the data stored at the memory location of cBuffer, they each merely set the length to zero. You can confirm this by watching cBuffer in the debugger. Which one to use is just a matter of personal preference. I like CLEAR_BUFFER because it?s the easiest for me to type: Cl<tab><space><variable name>
Joe
I got into that trouble in the past, so I'm using the BUFFER='' method, which will be executed Immediately.
CLEAR_BUFFER doesn?t execute when it?s called?? That?s a new one on me. Do you know if that?s documented anywhere?
Thanks for the insight. I guess I should switch to = ?? from now on.
Joe
(But I used the BUFFER = '' also in the past - it was less to write in the times before auto suggestion ;-)
I most frequently use BUFFER = '' because it is most likely to describe at a glance what I am doing - setting a CHAR array (or whatever) to a null value. When doing what the original poster decribed, actually clearing a buffer because it got filled with junk, (modern comm ports never do that though, do they? /wink ). I use the CLEAR_BUFFER statement, again because it more accurately decribes what I am trying to do. In a case like that, end of mainline is fine.