Nick
Nice hearing from you.
Quote:
|
Originally Posted by Nicholishen
cowboy,
I did not know that mq4 could use pointers until recent. I ran some tests, and found that you don't need to declare the var as global because it uses the pointer to change the variables in memory.
|
Yes, but not really, what you did in the second example was to send the function the value of 'var a' when you called the function and re-asigned the 'var a' a new value of the return of function call. not quite the same.
Try this have a = 1; b=0; and call the function and pass it 'a' and have b= the return from the function. you will see that 'a' at the end will still equal 1 and 'b' will now equal 2. as 'a' was passed as value not referance and the function can not change its value. only if its passed by referance(&). If you are right then both 'a' and 'b' should equal 2 in the above case.
Arrays are handled a little differently then simple parameters. and declearing functions in a seperate libaray, You will find that it handles it differently expecially with arrays. If you are giving any of the parameters default values watch out if you are introducing the function from a libaray or include file as these defaults are not accepted in those cases.
If you look at codersguru post he has placed the '&' symble in the parameter declaration which passes the array by referance with out it complete arrays cannot be passed. You can pass single elements by value, but cannot pass complete arrays by value.
There is one more thing that cought my eye, your construction of the two procedural calls themselfs. I have not seen to meny people use the void type. There are two different types of Procedural Calls, MT only supports one directly the second one is more or less indirectly supported with the use of the void type declaration. The two procedural calls are Function Procedures and Routine Procedures.
your first example is a routine procedures as it returns nothing but performs a duty when called. It can be a stand alone statement as in your example or an element of a compound statement. It can not be assigned to a variable. The second example is a function procedure that returns a value and must be assigned to a variable, it cannot be used as a stand alone statement. The only thing that MT did was to introduce the void type to indirectly impliment routine procedures.
Leaving out the return statement although acceptible in your first example is not a good programing habit to get into. when useing the void type you should end the procdure with the 'return;' statment without the () just the return key word. This will make your code forwardly adaptable if MT impliments the full rules for procedural calls.
I must say you have learned a lot on the programing end of things sence your first posts here. If everone would give only half the efford you have given they would be better off,
The CockeyedCowboy