What does this warning means?

P

prashna

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
 
J

Joona I Palaste

prashna said:
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 ([email protected]) ---------------------------\
| 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
 
R

Robert Stankowic

prashna said:
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
 
P

pete

prashna said:
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.
 
A

Ashish

prashna said:
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
 
F

Fao, Sean

prashna said:
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)
{
...
}
 
J

Joona I Palaste

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 ([email protected]) ---------------------------\
| 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
 
F

Fao, Sean

Joona I Palaste said:
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.
 
B

Ben Pfaff

Joona I Palaste said:
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.
 
D

Dan Pop

In said:
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
 
G

goose

Fao said:
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,
 
D

Dan Pop

In said:
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
 
G

goose

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top