473,386 Members | 2,078 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,386 software developers and data experts.

Missing return value of a function

Hi,

In my code, I have a function which has a return value in the
declaration:

bool myFunction( int a) {
// my implmentation

}

how come the code still compile even if I don't have a return value
(neither true/false). How can I enforce that ? i am using gcc on
linux.

Thank you.

Mar 3 '06 #1
3 4178
Al************@gmail.com wrote:
In my code, I have a function which has a return value in the
declaration:

bool myFunction( int a) {
// my implmentation

}

how come the code still compile even if I don't have a return value
(neither true/false). How can I enforce that ? i am using gcc on
linux.


Ask in gnu.gcc.help (or gnu.g++.help). Often, if your compiler gives
you a warning, you can try "treat warnings as errors", and jack the
warning level all the way up.

Generally speaking, falling off the end of a function that is declared
as returning a value has _undefined_ behaviour, and no diagnostic is
required.

V
--
Please remove capital As from my address when replying by mail
Mar 3 '06 #2
Al************@gmail.com wrote in news:1141420868.941649.78800
@t39g2000cwt.googlegroups.com:
Hi,

In my code, I have a function which has a return value in the
declaration:

bool myFunction( int a) {
// my implmentation

}

how come the code still compile even if I don't have a return value
(neither true/false). How can I enforce that ? i am using gcc on
linux.


Ask in a newsgroup dedicated to your compiler. See what you can find by
looking through your compiler's documentation.

Mar 3 '06 #3

Victor Bazarov wrote in message ...
Al************@gmail.com wrote:
In my code, I have a function which has a return value in the
declaration:

bool myFunction( int a) {
// my implmentation
}

how come the code still compile even if I don't have a return value
(neither true/false). How can I enforce that ? i am using gcc on
linux.


Ask in gnu.gcc.help (or gnu.g++.help). Often, if your compiler gives
you a warning, you can try "treat warnings as errors", and jack the
warning level all the way up.


OP:
try -Wall
which includes:

-Wreturn-type
Warn whenever a function is defined with a return-type that defaults to int.
Also warn about any return statement with no return-value in a function whose
return-type is not void.
For C++, a function without return type always produces a diagnostic message,
even when -Wno-return-type is specified. The only exceptions are main and
functions defined in system headers.

--
Bob R
POVrookie
Mar 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: soup_or_power | last post by:
I'm passing the return from window.open as a function argument and getting the error "missing ] after element list" when tested with FireFox. Here is the relevant code. Many thanks for your help....
7
by: Carlos Martinez Garcia | last post by:
Hi all: I have a piece of code similar to this: bool MyClass::myMethod() { ... (there is no return) } I have a random behaviour. It depends on if I'm debuging the code or not. When I'm...
0
by: Jigar.Patel | last post by:
I have simple remoting server exposing following simple method. When I try to add webreference to this server in another project, it gives me following error: Custom tool error: Unable to import...
2
by: inventor | last post by:
I'm doing programming for my science prodject, and when I was programming (I'm building an alphebatizer) I ran into this bug: I've got an input box, but no button or output box. so I do some...
5
by: le0 | last post by:
Hello guys, Im really having a hard time doing this, I have a record set with the ItemNo field with the data type as Text. In the record that I have, I want to find the missing number in the...
4
by: Matt Kruse | last post by:
According to standards, if an option is selected and it has no VALUE attribute, the contents of the option tag is to be submitted. So: <select name="sel"> <option selected>Value</option>...
7
by: Lo'oris | last post by:
$name=$_GET; if (!$name) $name="value"; i can't figure out how to shorten this thing. Is there some kind of operator i don't know about?
25
by: Alex Popescu | last post by:
Hi all! I am pretty sure this has been asked a couple of times, but I don't seem to find it on the archives (Google seems to have a couple of problems lately). I am wondering what is the most...
17
by: Christoph Zwerschke | last post by:
I'm just reading PEP 3107 (function annotations) and wonder why exceptions are not mentioned there. I think it would be helpful if one could specify which exceptions can be raised by a function,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.