473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

What does this warning means?

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
12 2974
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

"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
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

"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

"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
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

"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
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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Madhur | last post by:
Hello what about this nice way to open a file in single line rather than using if and else. #include<stdio.h> void main() { FILE *nd; clrscr();...
15
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I'm trying to initialize an array of error messages, so that I can print out an error message by using the 'nth string in an array, e.g. printf("%s\n", messages); I'm still hazy on arrays of...
8
by: ranjeet.gupta | last post by:
warning C4013: 'localData' undefined; assuming extern returning int What the above warning exactly mean ?
26
by: Lasse Edsvik | last post by:
Hello I'm trying to build a simple COM+ app in vs.net using C# and i cant register it in component manager..... what more is needed than this: using System; using...
10
by: Protoman | last post by:
Could you tell me what's wrong with this program, it doesn't compile: #include <iostream> #include <cstdlib> using namespace std; class Everything { public: static Everything* Instance()
9
by: ziman137 | last post by:
Hi all, The results from following codes got me a bit confused. #include <stdio.h> #include <iostream> using namespace std; struct A {
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
13
by: Anonymous | last post by:
On MS site: http://msdn2.microsoft.com/en-us/library/esew7y1w(VS.80).aspx is the following garbled rambling: "You can avoid exporting classes by defining a DLL that defines a class with...
46
by: Kenny O'Clock | last post by:
This came up in a job interview, what is the output of the program below? I tried to compile and run it myself, but my compiler (lcc-win32) aborts with this errors.... Warning test2.c: 3 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.