Hi Jack Everett,
JE> Hmmm This may sound a little strange to you guys that have been doing
JE> this for awhile..But can someone please explain the use of void and
JE> tell me what it does when it is on the left, right and on both sides..
well, I can explain that in terms of 'right','left' and 'both' but you won't
get very far using that info..
There are three uses of the keyword 'void' that I immediatly recall:
1) Defining a function return value: this usage is sth. like this "void
myfunc() ", it means that the function returns NO value of any
sort , using pascal terminology, it is a procedure rather than a function..
C++ assumes a void return list if nothign is specified, ie.
"myfunc()"="void myfunc()"; an exception to this is class
constructors which always has a return value of a pointer to an instance to
the class in question. (left)
2) Defining a parameter list for a function : this does exactly the same
thing for the parameter list, that is the function has no parameter list, it
can not accept any values of any sort. eg : " mfunc(void)"; C++
assumes a void parameter list if nothing is written inside the brackets.
" myfunc()"=" myfunc(void)". (right)
3) Defining a void pointer: this usage is "void * "; a void
pointer may point to anything one you typecast it.
usage 1 and 2 may be combined to define a function that has no return value
and no parameter list.
I would like to remind you that 'C++ assumes' means those shortcuts are only
applicable to C++ not C. An empty parameter list in C means "there is no
information about the parameter list" not "the function takes no arguments".
And an empty return list may mean either "integer return value" with an old
style compiler or "the function returns nothing" with relatively new
compilers. So do not rely on them if you are trying to write portable C code
on a C++ compiler.
Berk
PS: Had you been a user at my bbs, you would have got a 'unknown identifier'
error as you have written 'void' with capital letters.. Don't forget C and
C++ are case sensitive. And I'm especially sensetive about it (origin line
may tell you why:-))
--- GoldED/386 2.50.A0715 UNREG
(2:431/327)
---------------
* Origin: void BBS where nothing but
|