| Subject: | How do I get a warning or error when returning values from functions returning void in GCC? |
|---|---|
| From: | bgutter <bgutter1@xxxxxxxxx> |
| Date: | Wed, 16 Jul 2008 13:36:21 -0700 (PDT) |
| Newsgroups: | gnu.gcc.help |
Hi,
The following code compiles with -Wall and -Werror with no error. This
is on GCC 3.4.6 running on Red Hat Enterprise Linux 4 on a 32-bit
Linux machine, nor will GCC 4.2.1 running on a 64-bit Linux machine
emit an error or warning:
void f3(int value)
{
(void)value;
return;
}
void f2(int value)
{
return f3(value);
}
void f1()
{
f2(23);
}
But this code does not compile, but fails with the error shown below:
void f4()
{
return 23;
}
Isrc/st.c: In function 'void f4()':
Isrc/st.c:35: error: return-statement with a value, in function
returning 'void'
Why? I believe that I have turned on -Wall which should have caught
this error. Other compilers such as the old Visual Studio 6 compiler
on Windows do report an error.
Is there some special compile option I should be using here?
Thanks,
bgutter
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Problem migrating to EM64T, emilbarton |
|---|---|
| Next by Date: | Re: Problem migrating to EM64T, Paul Pluzhnikov |
| Previous by Thread: | Problem migrating to EM64T, emilbarton |
| Next by Thread: | Re: How do I get a warning or error when returning values from functions returning void in GCC?, Thomas Maeder |
| Indexes: | [Date] [Thread] [Top] [All Lists] |