We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › what does void mean
Page Index Toggle Pages: 1
what does void mean? (Read 635 times)
what does void mean?
Jan 15th, 2009, 6:08am
 
I read in the reference it means no value is returned. But what does that mean? Why would I want to or would I not want to return a value? What's the point of void anyway? WHy can't it just be draw(), or setup()?

For some reason the old answer "void doesn't return a value" doesn't mean much to my brain.

blatant noob q i know...

:S
Re: what does void mean?
Reply #1 - Jan 15th, 2009, 6:34am
 
Hey!
void is (in most langauges) a keyword to describe a function that does not return any value. for example;
Code:
void isPrime(int i) //does not return a value when called
boolean isPrime(int i) //returns a boolean (true or false) value


Your would call each function respectively:
Code:
isPrime(5); //no value is returned
boolean t = isPrime(5); //t = true;


BTW special functions CANNOT be changed (unless they are overwritten in a class). For instance, you cannot make a function called int draw() as it will conflict with void draw() which is already defined.
If i were you, I would look at a beginning tutorial of java/C. You dont even need to code anything, just follow what the author says.
Goodluck Smiley
Re: what does void mean?
Reply #2 - Jan 15th, 2009, 11:31am
 
Good explanation above, I will just add some info.

Note that class constructors have no return type!
So the void brings some information: 1) This function is not a constructor, 2) It states explicitely the nature of the function.

Unlike some languages (JavaScript, Lua, JavaFX...), there is no "function" keyword marking functions as such. So the syntax of a function is:
<return type> [<optional visibility modifiers>] <function name>([<optional list of parameters>]) { <body of function> }

The problem is that code like: f() { /* Some code */ } would be seen as: call of f, start a block (delimiting a scope), code, end the block. You can start a block anywhere, it doesn't have to follow a conditional or such.
So it would no longer be a function definition but a function call!
Page Index Toggle Pages: 1