Summary: | The return value of a Basic function is not initialized | ||
---|---|---|---|
Product: | LibreOffice | Reporter: | Andreas Heinisch <andreas.heinisch> |
Component: | BASIC | Assignee: | Not Assigned <libreoffice-bugs> |
Status: | NEW --- | ||
Severity: | normal | CC: | himajin100000 |
Priority: | medium | ||
Version: | Inherited From OOo | ||
Hardware: | All | ||
OS: | All | ||
See Also: |
https://bugs.documentfoundation.org/show_bug.cgi?id=143582 https://bugs.documentfoundation.org/show_bug.cgi?id=146742 https://bugs.documentfoundation.org/show_bug.cgi?id=149622 |
||
Whiteboard: | |||
Crash report or crash signature: | Regression By: | ||
Attachments: | There is six bugs in code we successfully identified it so we mentioned these in this picture with code |
Description
Andreas Heinisch
2021-10-11 12:31:28 UTC
Isn't this even a feature? The "function name" return variable is static and keeps its value if not initialized otherwise? From https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/function-statement "If Static isn't used, the value of local variables is not preserved between calls." So I thought that the value should be cleared. How about recursions? Created attachment 176035 [details]
There is six bugs in code we successfully identified it so we mentioned these in this picture with code
#include <iostream>
using namespace std;
public bool password(string password){ //first check password then user run this program
string pass="ak2563";
bool=false;
if (pass==password){ // bug:2 we cant compare string like that
bool=true;
return true;
}
else {
return bool;
}
}
int main()
{
int power;
float number, result = 0; // bug:6 we need to initialized result=1 not "0"
int times_of_multiply; //Bugs:1 This veriable times_of_multiply not used in entire program
cout << "Enter number and number respectively: ";
cin >> number >> power;
cout << number << "^" << power << " = ";
while (power != 1) { // bug:3 not getting our expected result
result *= number;
--number; // bug:4 we need to decrement power not number
}
cout << result, number; // bug:5 we dont need to print number we need to print just result
return 0;
}
#include <iostream> using namespace std; public bool password(string password){ //first check password then user run this program string pass="ak2563"; bool=false; if (pass==password){ // bug:2 we cant compare string like that bool=true; return true; } else { return bool; } } int main() { int power; float number, result = 0; // bug:6 we need to initialized result=1 not "0" int times_of_multiply; //Bugs:1 This veriable times_of_multiply not used in entire program cout << "Enter number and number respectively: "; cin >> number >> power; cout << number << "^" << power << " = "; while (power != 1) { // bug:3 not getting our expected result result *= number; --number; // bug:4 we need to decrement power not number } cout << result, number; // bug:5 we dont need to print number we need to print just result return 0; } The content of attachment 176035 [details] has been deleted for the following reason:
spam
(In reply to Andreas Heinisch from comment #2) > From > https://docs.microsoft.com/en-us/office/vba/language/reference/user- > interface-help/function-statement > > "If Static isn't used, the value of local variables is not preserved between > calls." > > So I thought that the value should be cleared. How about recursions? I've not seen VBA documentation that makes it clear that the name of a function is a "local" variable. But all versions of VBA treat it that way. The name of a function is a local variable of that function, and is initialised at every call of that function. Regarding recursion 'static' is not normally used with recursive VBA functions -- it kind of defeats the purpose in common cases. Already repro with OOo 3.2 |