By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,677 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

What does this warning means?

P: n/a
Hi all,
I am new to C and I am working on some simple programs.I am getting
the following warning which I am not able to find what it is, please
let me know what is causing this warning.Also What happens if I ignore
this warning?

inttoascii.c:38: warning: control reaches end of non-void function
Nov 13 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
prashna <va******@rediffmail.com> scribbled the following:
Hi all,
I am new to C and I am working on some simple programs.I am getting
the following warning which I am not able to find what it is, please
let me know what is causing this warning.Also What happens if I ignore
this warning? inttoascii.c:38: warning: control reaches end of non-void function


It means that you have defined a function returning other than void
(which means that it returns any type that you can assign values to),
and you've left a path for it to execute fully without ever encountering
a "return" statement. This means, if the function ever takes that path,
the returned value will be useless.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"He said: 'I'm not Elvis'. Who else but Elvis could have said that?"
- ALF
Nov 13 '05 #2

P: n/a

"prashna" <va******@rediffmail.com> schrieb im Newsbeitrag
news:d4**************************@posting.google.c om...
Hi all,
I am new to C and I am working on some simple programs.I am getting
the following warning which I am not able to find what it is, please
let me know what is causing this warning.Also What happens if I ignore
this warning?
Redmont will be destroyed by a nuclear attack, perhaps :)

inttoascii.c:38: warning: control reaches end of non-void function


The cause maybe something like
int foo(int bar)
^^^^
{
/*do something with bar*/
/*and then you forgot to return something, like*/
return 0;
^^^^^^^^^^
}

Robert
Nov 13 '05 #3

P: n/a
prashna wrote:

Hi all,
I am new to C and I am working on some simple programs.I am getting
the following warning which I am not able to find what it is, please
let me know what is causing this warning.
You should post code which you believe may cause me to
get a similar warning when I copy it and try to compile it.

I'm guessing that you have a function definition which
should have the keyword "void", in front of it, but doesn't.
Also What happens if I ignore
this warning?

inttoascii.c:38: warning: control reaches end of non-void function


I would advise you to pay attention to compiler warnings until
you have been programming for about ten years,
and then to reconsider the matter.

--
pete
Nov 13 '05 #4

P: n/a

"prashna" <va******@rediffmail.com> wrote in message
news:d4**************************@posting.google.c om...
Hi all,
I am new to C and I am working on some simple programs.I am getting
the following warning which I am not able to find what it is, please
let me know what is causing this warning.Also What happens if I ignore
this warning?

inttoascii.c:38: warning: control reaches end of non-void function


It means that one of your control paths doesnt return a value.

-A
Nov 13 '05 #5

P: n/a

"prashna" <va******@rediffmail.com> wrote in message
news:d4**************************@posting.google.c om...
Hi all,
I am new to C and I am working on some simple programs.I am getting
the following warning which I am not able to find what it is, please
let me know what is causing this warning.Also What happens if I ignore
this warning?

inttoascii.c:38: warning: control reaches end of non-void function


I'm only assuming here but since you're a newbie, I'd say that you have
forgotten a return statement in main().

/* Correct */
int main(void)
{
...
return 0;
}

--------------------

/* Incorrect */
int main(void)
{
...
}
Nov 13 '05 #6

P: n/a
Fao, Sean <en**********@yahoo.comi-want-no-spam> scribbled the following:
"prashna" <va******@rediffmail.com> wrote in message
news:d4**************************@posting.google.c om...
Hi all,
I am new to C and I am working on some simple programs.I am getting
the following warning which I am not able to find what it is, please
let me know what is causing this warning.Also What happens if I ignore
this warning?

inttoascii.c:38: warning: control reaches end of non-void function
I'm only assuming here but since you're a newbie, I'd say that you have
forgotten a return statement in main(). /* Correct */
int main(void)
{
...
return 0;
} -------------------- /* Incorrect */
int main(void)
{
...
}


Actually main() is a special case. As long as main() is declared as
returning int, falling off main() without returning anything counts
as returning 0. This applies *ONLY* to main(). In all other functions,
if you say you're returning an int, remember to return that int!

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Remember: There are only three kinds of people - those who can count and those
who can't."
- Vampyra
Nov 13 '05 #7

P: n/a

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bl**********@oravannahka.helsinki.fi...
Fao, Sean <en**********@yahoo.comi-want-no-spam> scribbled the following:
"prashna" <va******@rediffmail.com> wrote in message
news:d4**************************@posting.google.c om...
Hi all,
I am new to C and I am working on some simple programs.I am getting
the following warning which I am not able to find what it is, please
let me know what is causing this warning.Also What happens if I ignore
this warning?

inttoascii.c:38: warning: control reaches end of non-void function

I'm only assuming here but since you're a newbie, I'd say that you have
forgotten a return statement in main().

/* Correct */
int main(void)
{
...
return 0;
}

--------------------

/* Incorrect */
int main(void)
{
...
}


Actually main() is a special case. As long as main() is declared as
returning int, falling off main() without returning anything counts
as returning 0. This applies *ONLY* to main(). In all other functions,
if you say you're returning an int, remember to return that int!


Aww yes, thank you for reminding me; I always forget that one.
Nov 13 '05 #8

P: n/a
Joona I Palaste <pa*****@cc.helsinki.fi> writes:
Actually main() is a special case. As long as main() is declared as
returning int, falling off main() without returning anything counts
as returning 0. This applies *ONLY* to main().


It only applies in C99, too.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 13 '05 #9

P: n/a
In <87************@pfaff.stanford.edu> Ben Pfaff <bl*@cs.stanford.edu> writes:
Joona I Palaste <pa*****@cc.helsinki.fi> writes:
Actually main() is a special case. As long as main() is declared as
returning int, falling off main() without returning anything counts
as returning 0. This applies *ONLY* to main().


It only applies in C99, too.


C89 doesn't require an explicit return either, it's just that the
semantics of a missing return value are different.

Both standards also allow other non-void functions not to return anything,
as long as the caller doesn't attempt to use their return value.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #10

P: n/a
"Fao, Sean" <en**********@yahoo.comI-WANT-NO-SPAM> wrote in message news:<D7****************@news.abs.net>...
"prashna" <va******@rediffmail.com> wrote in message
news:d4**************************@posting.google.c om...
Hi all,
I am new to C and I am working on some simple programs.I am getting
the following warning which I am not able to find what it is, please
let me know what is causing this warning.Also What happens if I ignore
this warning?

inttoascii.c:38: warning: control reaches end of non-void function


I'm only assuming here but since you're a newbie, I'd say that you have
forgotten a return statement in main().

/* Correct */
int main(void)
{
...
return 0;
}

--------------------

/* Incorrect */
int main(void)
{
...
}


itym s/main/foo ?

goose,
Nov 13 '05 #11

P: n/a
In <ff**************************@posting.google.com > ru**@webmail.co.za (goose) writes:
"Fao, Sean" <en**********@yahoo.comI-WANT-NO-SPAM> wrote in message news:<D7****************@news.abs.net>...
"prashna" <va******@rediffmail.com> wrote in message
news:d4**************************@posting.google.c om...
> Hi all,
> I am new to C and I am working on some simple programs.I am getting
> the following warning which I am not able to find what it is, please
> let me know what is causing this warning.Also What happens if I ignore
> this warning?
>
> inttoascii.c:38: warning: control reaches end of non-void function


I'm only assuming here but since you're a newbie, I'd say that you have
forgotten a return statement in main().

/* Correct */
int main(void)
{
...
return 0;
}

--------------------

/* Incorrect */
int main(void)
{
...
}


itym s/main/foo ?


He's wrong either way. An int foo() that doesn't return anything is not
a priori incorrect: it depends on what the caller does with its return
value.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #12

P: n/a
Da*****@cern.ch (Dan Pop) wrote in message news:<bl**********@sunnews.cern.ch>...
In <ff**************************@posting.google.com > ru**@webmail.co.za (goose) writes:
"Fao, Sean" <en**********@yahoo.comI-WANT-NO-SPAM> wrote in message news:<D7****************@news.abs.net>...
"prashna" <va******@rediffmail.com> wrote in message
news:d4**************************@posting.google.c om...
> Hi all,
> I am new to C and I am working on some simple programs.I am getting
> the following warning which I am not able to find what it is, please
> let me know what is causing this warning.Also What happens if I ignore
> this warning?
>
> inttoascii.c:38: warning: control reaches end of non-void function

I'm only assuming here but since you're a newbie, I'd say that you have
forgotten a return statement in main().

/* Correct */
int main(void)
{
...
return 0;
}

--------------------

/* Incorrect */
int main(void)
{
...
}


itym s/main/foo ?


He's wrong either way. An int foo() that doesn't return anything is not
a priori incorrect: it depends on what the caller does with its return
value.


true. but (and theres always a "but":-) the message that the OP was getting
was a warning, not an error. in which case even the "int main" example/fix
would make the warning correctly go away. the "error" could be that Sean Fao
should not have labeled the no-return main as "incorrect".
goose,
Nov 13 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.