Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > control reaches the end of non-void function

Reply
Thread Tools

control reaches the end of non-void function

 
 
Thomas Barth
Guest
Posts: n/a
 
      10-24-2005
Hi
could someone explain to me why the compiler outputs a warning that the
control reaches the end of a non void function?

int main(void) {
...
pthread_t thrCallOp, thrHangUp;
pthread_create(&thrCallOp, NULL, &callOp, NULL);
pthread_create(&thrHangUp, NULL, &setHangUp, NULL);

pthread_join(thrCallOp, NULL);
pthread_join(thrHangUp, NULL);

...
return EXIT_SUCCESS;
}

void *callOp() {
while(1) {
if ('q' == ch) {
break;
}
...
sleep(1);
}
} //end of non-void function


Thanks in advance,
T h o m a s B
 
Reply With Quote
 
 
 
 
David Resnick
Guest
Posts: n/a
 
      10-24-2005
Thomas Barth wrote:
> Hi
> could someone explain to me why the compiler outputs a warning that the
> control reaches the end of a non void function?
>
> int main(void) {
> ...
> pthread_t thrCallOp, thrHangUp;
> pthread_create(&thrCallOp, NULL, &callOp, NULL);
> pthread_create(&thrHangUp, NULL, &setHangUp, NULL);
>
> pthread_join(thrCallOp, NULL);
> pthread_join(thrHangUp, NULL);
>
> ...
> return EXIT_SUCCESS;
> }
>
> void *callOp() {
> while(1) {
> if ('q' == ch) {
> break;
> }
> ...
> sleep(1);
> }
> } //end of non-void function
>
>
> Thanks in advance,
> T h o m a s B


You said it would return a pointer -- a void* -- and returned nothing.
At least that is as far as I can tell from your partial code. The
compiler assumes that you meant what you told it, and that it is an
error to reach the end of the function without returning a void*.
Did you mean it to be void callOp(void)?

-David

 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      10-24-2005
In article <(E-Mail Removed)>,
Thomas Barth <(E-Mail Removed)> wrote:
>could someone explain to me why the compiler outputs a warning that the
>control reaches the end of a non void function?


>void *callOp() {
> while(1) {
> if ('q' == ch) {
> break;
> }
> ...
> sleep(1);
> }
>} //end of non-void function


That isn't a void function, that is a void* function. The compiler
is expecting you to return a void*, but instead you just fall off
the end of the function.


As to what an appropriate return value is for the start argument
to pthread_create: you would have to inquire about that in a newsgroup
that deals with threads. Threads are not part of the C standard, so
we avoid talking about them in comp.lang.c .
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes
 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      10-24-2005
Thomas Barth wrote:
> Hi
> could someone explain to me why the compiler outputs a warning that the
> control reaches the end of a non void function?


Because control reaches the end of a function that returns a ptr-to-void
and yet you don't return anything. I would think that the warning is
completely clear.

[...]
> void *callOp() {
> while(1) {
> if ('q' == ch) {
> break;
> }
> ...
> sleep(1);
> }
> } //end of non-void function
>
>
> Thanks in advance,

^^^^^^^^^^^^^^^^^
Bill Collector Jargon
 
Reply With Quote
 
Thomas Barth
Guest
Posts: n/a
 
      10-24-2005
Am 10/24/2005 08:02 PM schrieb Walter Roberson:

>
> That isn't a void function, that is a void* function. The compiler
> is expecting you to return a void*, but instead you just fall off
> the end of the function.
>


Yes, but I dont get the warning if I comment the if block

void *callOp() {
while(1) {
/*
if ('q' == ch) {
break;
}
*/
...
sleep(1);
}
} //no warning

Regards,
T h o m a s B
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-24-2005
Thomas Barth <(E-Mail Removed)> writes:
> Am 10/24/2005 08:02 PM schrieb Walter Roberson:
>> That isn't a void function, that is a void* function. The compiler
>> is expecting you to return a void*, but instead you just fall off
>> the end of the function.

>
> Yes, but I dont get the warning if I comment the if block
>
> void *callOp() {
> while(1) {
> /*
> if ('q' == ch) {
> break;
> }
> */
> ...
> sleep(1);
> }
> } //no warning


Without the break statement, it's not possible for the while loop to
terminate -- thus you can never reach the end of the function.

The compiler might reasonably have warned you about declaring that the
function returns void*, when in fact it can never return anything, but
it doesn't. Neither warning is required; it's up to the whim of the
compiler writer to decide what warnings to issue (as long as it emits
any diagnostics required by the standard).

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Skarmander
Guest
Posts: n/a
 
      10-24-2005
Thomas Barth wrote:
> Am 10/24/2005 08:02 PM schrieb Walter Roberson:
>
>>
>> That isn't a void function, that is a void* function. The compiler
>> is expecting you to return a void*, but instead you just fall off
>> the end of the function.
>>

>
> Yes, but I dont get the warning if I comment the if block
>
> void *callOp() {
> while(1) {
> /*
> if ('q' == ch) {
> break;
> }
> */
> ...
> sleep(1);
> }
> } //no warning
>


That's because you created an infinite loop (assuming "..." isn't
standing in for any statements that can alter control flow). Control
never reaches the end of the function, ergo.

Your compiler is trying to communicate! Listen to it carefully!

S.
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      10-24-2005
In article <(E-Mail Removed)>,
Thomas Barth <(E-Mail Removed)> wrote:
>Am 10/24/2005 08:02 PM schrieb Walter Roberson:



>> That isn't a void function, that is a void* function. The compiler
>> is expecting you to return a void*, but instead you just fall off
>> the end of the function.



>Yes, but I dont get the warning if I comment the if block


>void *callOp() {
> while(1) {
> /*
> if ('q' == ch) {
> break;
> }
> */
> ...
> sleep(1);
> }
>} //no warning


That's because the compiler is smart enough to notice that you
have an infinite loop in the while() that can never be exitted,
making it impossible to return anything from the function.
--
I am spammed, therefore I am.
 
Reply With Quote
 
Christopher Benson-Manica
Guest
Posts: n/a
 
      10-24-2005
Thomas Barth <(E-Mail Removed)> wrote:

> void *callOp() {
> while(1) {
> /* if ('q' == ch) {
> break;
> } */
> sleep(1);
> }
> } //no warning


Your compiler is smart enough to know that when you comment out the
portion of the code in question, there is no exit from the while loop,
and thus control never reaches the end of your non-void function.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Second long argument to a JNI call on a Win32 DLL contains zero when it reaches the DLL pcarr01 Java 3 02-17-2005 09:30 AM
Want XP Pro to boot up without entering passwords or stopping until it reaches the desktop. William Pierce Computer Support 2 01-24-2005 09:33 PM
IE Task Bar never reaches 100% Steve Flitcroft ASP .Net 0 08-09-2004 01:40 PM
Mozilla Tips reaches 100 Tips and 90,000 Visits Cornelius Fichtner Firefox 0 12-18-2003 11:50 PM
control reaches end of non-void function John Buckley C Programming 8 10-14-2003 11:54 AM



Advertisments