It is currently Wed May 24, 2017 6:24 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Minor suggestion for use of pre/postfix operators
Unread postPosted: Sat Apr 15, 2017 9:29 am 
Offline
User avatar

Joined: Mon Mar 27, 2017 2:42 pm
Posts: 14
I recently wrote a short function that returns four 8-bit values. But of course a function can only return one value. Easy enough to return as a single 32-bit number with shift and add instructions. Then main program just extracts the values in the opposite way they were packed:

Code:
DO
   a[++v]=BAND(x,255)
   x=SHIFT(x,8)
UNTIL v=4


Simple, right? Until I went to print them out with this routine:
Code:
DO
  PRINT RIGHT$("0"+HEX$(a[v--]),2);" | ";
UNTIL v=0


Which only printed the second and fourth values. This drove me nuts until I read the manual on pre and postfix operators, which referred me to "User Defined Functions", which largely clarified everything. I simply took out the postfix and put a v-=1 before the until. My suggestion is, instead of referring the reader to "User Defined Functions", shouldn't it just tell you in the pre- and postfix section, that they don't work within any function, not just the user defined? Just a thought.
Peace,

ReNoob


Top
 Profile  
 
 Post subject: Re: Minor suggestion for use of pre/postfix operators
Unread postPosted: Mon Apr 17, 2017 12:26 pm 
Offline
User avatar

Joined: Thu Nov 21, 2013 7:00 pm
Posts: 638
The pre/post fix Ops you used did work.
The problem is with the PRINT command which evaluates functions twice during parsing.
(see "Print with User-Defined Functions" in the manual)

The User-Defined-Functions relationship with function calls you referred to is something different.
When you call a function by reference, it expects a variable. If you pre/post Op it, it becomes a
value (which cannot be passed by reference).

_________________
- Failure is not an option. It is bundled with the software. -


Top
 Profile  
 
 Post subject: Re: Minor suggestion for use of pre/postfix operators
Unread postPosted: Mon Apr 17, 2017 2:43 pm 
Offline
User avatar

Joined: Mon Mar 27, 2017 2:42 pm
Posts: 14
You were correct about the print statement, of course. Codewise though, I feel that making an assignment/print out of it ("Z$=RIGHT$(......), followed by PRINT Z$;" |"; is less efficient than just eliminating the postfix. I'm still just the student here, I could be wrong.
Peace
'Noob


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron
suspicion-preferred