You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
Be sure to init values using BYREF (the default.)
This might be noted in the docs. I knew better, just bringing it up.
Code:
FUNCTION PBMAIN () AS LONG
LOCAL x, y, z AS LONG
x = 99: y = 100: z = 101
CALL test (x, y, z)
? "Did you expect" + STR$(x) + "," + STR$(y) + "," + STR$(z)
END FUNCTION
FUNCTION Test(a AS LONG, b AS LONG,c AS LONG) AS LONG
END FUNCTION
... the compiler failed to detect the absence of any {statements}, ( "{}" means REQUIRED; "[]" are optional ), so I guess I was lucky my variables weren't corrupted.
I mentioned this because it took me some time to debug some code and wondered if the help file mentioned unused variables are
not init. This is from the help file on the CALL statement. I think it might be expanded.
When a parameter is passed by reference, it consists of a 4-byte address of the data. In this case, the original data can be modified by the procedure.
No, I expect others to expect that since it is not mentioned in the docs.
I've known about it for many years and just thought it should be mentioned. It took me too long to find an error and should have
been looking for this. Maybe I should not have brought this up.
If the documentation was confusing to you, then of course you should bring it up. But you really should report this to [email protected] and call it a "documentation improvement suggestion."
It can get in line behind the 863 such suggestions I have sent in and have been "referred to the Documentation Team."
(What, you thought the New York Mets were the most overpaid team in this country?)
>Wait a minute... you were not somehow lead to believe variable parameters passed by reference were initialized on entry to a procedure, were you?
Is this thread a joke. Three variables are passed BYREF to a function that doesn't change them and the calling program demonstrates that checked in a couple versions of the compiler.
I don't understand why there is a discussion about initialisation. Of course the compiler does it automatically, X, Y and Z are local variables which the compiler automatically initialises to zero RTFM, if the program does not set a value then that value of zero would be passed BYREF and as they are not changed then they would remain at zero. How can a variable, passed BYREF be in any other way "initialised", thats done when the variable is created, not when it is passed.
Update the documentation? You are joking, what replace a set of curly brackets with square brackets? Picky, Picky. I have sent a couple of suggestions for documentation improvements but this is getting to a rediculous level.
To be honest I read this thread many times before replying as I kept thinking it had to be an old one dated April 1.
Update the documentation? You are joking, what replace a set of curly brackets with square brackets?
Well, that may not be a documentation error; it may in fact be a compiler error.
The doc says {statements} is required, yet the compiler compiled it in spite of the fact the procedure 'Test' contains no statements.
Either...
A. The documentation is in error
OR
B. The compiler should have refused to compile the program, failing on a "Required statement(s) missing" error.
... the compiler failed to detect the absence of any {statements}, ( "{}" means REQUIRED; "[]" are optional ), so I guess I was lucky my variables weren't corrupted.
MCM
Actually, NO brackets "[]" or "{}" means REQUIRED.
{} means 0 or more. [] means optional, 0 or 1 .
So a function can have 0 statements and is completely valid.
#COMPILE EXE
#DIM ALL
#DEBUG ERROR ON
FUNCTION PBMAIN () AS LONG
ON ERROR RESUME NEXT
IF 1 THEN
'nothing here {statements}
ELSEIF 2 THEN
'nothing here {statements}]
ELSE
'nothing here too {statements}]
END IF
? ERROR$(ERR)
END FUNCTION
"The trouble with quotes on the Internet is that you can never know if they are genuine." - Abraham Lincoln.
Yes, Arthur's code should compile and run and yes, there are several places in the documentation that the syntax is incorrect. Whenever I find one, I send it in to support.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment