Need to use the file access commands for a add in I have been making, but i know I am doing something very stupid, but for the past 3 hours have come up short on what that is.
The most basic segmant of code to show this would be the following:

Code:

unsigned short name[30]={'\\','\\','f','l','s','0','\\','t','e','s','t','e','r','.','p','y',0};
handle=Bfile_OpenFile_OS(name,READ,0);
if (1){
   void *vars[1]={&handle};
   basic_printer8(NULL,"handle %i",vars,2,0,50,0,65535,NULL);
   }
GetKey(&key);

For some reason the handle always ends up being some random number not always negative or positive. No matter if the file tester.py exists or not.

I have no idea what I am doing wrong.
So a few things here:
  • You should be checking the result of the Bfile_OpenFile_OS() system call.
  • What is basic_printer8? Assuming it uses printf-style formatting, %i is fine, but %d would be more correct here.
  • Nit:might as well make name be const. And let name be the correct length (in this case, 17) without specifying it.
It's confusing to me that you get random positive and negative numbers that don't seem to correlate with the existence of the tester.py file. I would expect this code to look like:


Code:
const unsigned short filename[] = {'\\','\\','f','l','s','0','\\','t','e','s','t','e','r','.','p','y',0};
int handle = -1;
if (0 > (handle = Bfile_OpenFile_OS(name, 0x01))) { //_OPENMODE_READ
    void* vars[] = {&handle};
    basic_printer8(NULL,"handle %d",vars,2,0,50,0,65535,NULL);
} else {
    void* vars[] = {&handle};
    basic_printer8(NULL,"Failed to open file: %d",vars,2,0,50,0,65535,NULL);
}
GetKey(&key);
A bit more info would be aside from some extraneous warnings I disabled there are no warning thrown out by GCC.
Quote:
A bit more info would be aside from some extraneous warnings I disabled there are no warning thrown out by GCC.

There's no such thing as an extraneous warning. Wink What are the warnings?
They really are just there to fill the terminal with spam.


Code:
#pragma GCC diagnostic push
//the stuff I definatly want gone
#pragma GCC diagnostic ignored "-Wreturn-type"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"

#pragma GCC diagnostic ignored "-Wchar-subscripts"
#pragma GCC diagnostic ignored "-Wmain"
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#pragma GCC diagnostic ignored "-Wparentheses"
//the stuff that I probably want gone
#pragma GCC diagnostic ignored "-Wcomment"
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
#pragma GCC diagnostic ignored "-Wunused-label"
//Hmmm maybe?
#pragma GCC diagnostic ignored "-Wunused-value"


Also when I comment out said lines no warnings are in the section of testing code I posted.

Quick question to make testing easier, if the function is working properly would it return any positive number or would it return a number in the range of 0-15?
Ok it has gotten weirder, I swear that is wasn't like this when I was previously testing, but now if the file doesn't exist it always seems to return -1.

And if it does then it either returns a non -1 negative number or will return 2^24+something. With me not being sure what prompts either result while the code is different between the 2 testing programs I made, the Bfile reference is the same among both of them and yet each of the different testing progs consistently gives that different result.

Is it expected behavior for it to return 2^24+something small, if the file does exist?
I finally figured out the issue.

Since I was just testing if the Bfile_OpenFile_OS command worked in a vacuum I never used any other Bfile commands. As such I never used the CloseFIle command. It seems that the files a program has open are never closed upon the program exiting/ opening a different program.
Resulting in it either failing or giving the next file handle. Not sure what specifically causes either result but at least the issue is fixed.
I'm very surprised to hear that file handles are not closed when a different add-in is run and then your program is re-run, but I'm glad you were able to solve your issue.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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 vote in polls in this forum

 

Advertisement