Void functions without return

Dears, I’ve recently learned that void functions cannot return any variable. I’ve also read that if it is int type it would be possible.

Can you confirm that?

Because I’ve a code that works fine for 1 month and it includes global variable int and bool conditions. Attached you can see full code. Check void DisplayAlarmTime(). It uses several global int variables and I can transfer the changes of that variables within the function to any other functions or void loop() function as well.

Now I’m writing a new code to simplify the previous code and wonder how it works.

Irrigation_and_Curtain_System.ino (24.1 KB)

Yes you can modify global variables. That’s not the same as returning a variable. I think you should google “C++ functions” and do some reading on how functions work in C++. You seem to have some basic misconceptions.

Start here.

Thanks for the information. I've already read what is written on the link. Actually this question arised when I read that specific article. So In that article it states that I need to use return to get value of the variable outside. However my question is if so how my attached code works? It makes me think that this is not a valid assumption.

I doubt many people want to wade through 24KB of unrelated code to answer a question about such a fundamental aspect of the language. Instead, you should make an MCVE. This is the smallest possible code that's complete, compiles, and demonstrates the issue you're trying to understand.

So In that article it states that I need to use return to get value of the variable outside. However my question is if so how my attached code works? It makes me think that this is not a valid assumption.

Please post exactly what in the reference is confusing you.

The reference does focus on return values and does not explicitly cover what DeltaG posted in reply #1 about scope and functions modifying global variables.

If you are confused, others may be as well, and there is a github site for proposing modifications to the reference material

You may wish to propose a change to the documentation (submit an issue) in a way which clarifies things for you, and if your confusion and proposal make sense, the documentation will be changed.

gfvalvo: I doubt many people want to wade through 24KB of unrelated code to answer a question about such a fundamental aspect of the language. Instead, you should make an MCVE. This is the smallest possible code that's complete, compiles, and demonstrates the issue you're trying to understand.

I understand your concern but actually for that reason I've stated where exactly to look

gunaygurer: Check void DisplayAlarmTime(). It uses several global int variables and I can transfer the changes of that variables within the function to any other functions or void loop() function as well.

cattledog: If you are confused, others may be as well, and there is a github site for proposing modifications to the reference material https://github.com/arduino/reference-en

Of course I would propose them a modification but I'm not sure if I miss something. If you also think that you can return a value without return function then I can propose.

Of course I would propose them a modification but I'm not sure if I miss something. If you also think that you can return a value without return function then I can propose.

You are not returning a value without a return function. You are modifying a global variable within a function.

From the reference article on "Scope"

A global variable is one that can be seen by every function in a program.

gunaygurer: Thanks for the information. I've already read what is written on the link. Actually this question arised when I read that specific article. So In that article it states that I need to use return to get value of the variable outside. However my question is if so how my attached code works? It makes me think that this is not a valid assumption.

Ok then forget the crappy Arduino documentation and go read a C++ tutorial. There’s a difference between using a global in a function and modifying it and returning a variable. You don’t need any return to modify a global. That’s not what return is about.

You need to learn what return actually does.

Put simply if the function returns a value you can use it as "X = func(para);" and X will be set to the returned value.

If it's a void function which doesn't return anything you call it using just "func1(para1);". It might or might not change some GLOBAL variables but it isn't returning anything.

Steve