Have you noticed "void function"?

I have noticed a lot of beginners think that functions with no return value, or "void functions", are different from other functions. It seems to be in their head that they cannot treat them the same...

Has anyone else noticed this?
The fact is they can't treat these the same. From a semantic point of view, void functions, in order to have any effect at all must have side effects. Whereas functions which return a value are often "pure" functions, with no side effects.
I mean in terms of designing code, they seem to consider them as completely different rather than only thinking "Oh, I can't do var = VoidReturningFunc()"
Well, if you think about it, void functions are not functions (as in mathematics). Thus they are called procedures.
Though I haven't noticed anyone treating them weirdly, I think.
So, you haven't noticed the threads "problem in void function" and the homework assignments "2 void functions and 3 value functions"?
Nope. :)
It is a common beginner's issue to try and wrap your head around void. You see a small spate of these questions every semester.
Void functions are nothing on void * in terms of confusion, especially when they are used for a stupid approximation of object encapsulation in C.
(The smart way to get real encapsulation in C is to forward-declare structs in a header, and then define them in the internal code, as done in stdio.)
Last edited on
Yeah, I've never really noticed anyone treating them differently.
I have. There have definitely been posts recently in which people talked about "void functions", but never "int functions" or "double functions".
I see newbies often using "void functions" that modify global variables as a workaround for not understanding parameter passing.
Last edited on
I sometimes forget about void when writing my void member functions. ;)
And to my delight the compiler catches an error: I forgot to specify I'm not returning anything.
I sometimes forget about std::string when writing my std::string member functions. ;)
And to my delight the compiler catches an error: I forgot to specify I'm returning something.
closed account (43RGz8AR)
@Catfish I can't help but notice that a lot of the time you deserve every bit of hotheadedness Duoas and other elders give you.

On topic I have also noticed people thinking of them weird but not on the forums as I am pretty new here. I tutor for a college, and every once in awhile I have to go through explaining what void functions really are/or do, much like hamsterman just did.
Well, if you think about it, void functions are not functions (as in mathematics). Thus they are called procedures.

@LB They can't treat them the same, which is where most of the errors I've seen come from. It also brings in pointer, reference, and parameter type errors.
Besides not expecting to get a value from the function, what is wrong with treating them exactly the same way as any other function?
Generally, any "void function" confusion is actually non-void confusion, i.e. not understanding what return values mean or how they work.
Topic archived. No new replies allowed.