473,396 Members | 1,970 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,396 software developers and data experts.

missing return

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 debuging it returns false, but in normal execution it
returns true.

I have no error/warnings when compile it. ¿Is it the right behaviour?

Thanks in advance
Nov 28 '05 #1
7 1615
Carlos Martinez Garcia wrote:
Hi all:

I have a piece of code similar to this:

bool MyClass::myMethod() {
... (there is no return)
}


A function declared to return a value of specific type must return a
value of that type. Else it is undefined what value would be returned.
The only exception is "main" which implicitly returns 0.

Nov 28 '05 #2
Neelesh Bodas wrote:
Carlos Martinez Garcia wrote:
Hi all:

I have a piece of code similar to this:

bool MyClass::myMethod() {
... (there is no return)
}


A function declared to return a value of specific type must return a
value of that type. Else it is undefined what value would be returned.
The only exception is "main" which implicitly returns 0.

It's not only undefined what value might be returned, it's undefined
behavior period. While small things like bools are probably returned
via registers and just result in indeterminate values, things that the
compiler has to do more involved copy semantics for (like returning
classes) might cause the application to blow up.
Nov 28 '05 #3
When programming a multithread application sometimes there are problems
in the synchronisation of each thread. Most of the type a bad
synchornisation may result on a missing return code or a return without
any sense. For further aid you may post the code you are working at so
we can see what the problem is.

Nov 28 '05 #4
If you are programming a multithread application you may obtain a
return ucode sing the debug feature of your compiler because using the
debugger may give the thread the time for doing whatever it's supposed
to do.

Nov 28 '05 #5

"Sigmathaar" <si********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
When programming a multithread application sometimes there are problems
in the synchronisation of each thread. Most of the type a bad
synchornisation may result on a missing return code or a return without
any sense. For further aid you may post the code you are working at so
we can see what the problem is.


Please quote the text of the message you're responding to.

The OP stated that there was no return (statement) for the function that was
declared to return a bool. That makes the code exhibit undefined behavior.
Threading is not relevant to the issue. If you declare a function to return
a value, then it must in fact return a value via a return statement.

-Howard

Nov 28 '05 #6
>I have no error/warnings when compile it
Check for compiler warning level. You should get either Error: function
does not return, or Warning: not all control paths return a value.

Other possibility - you use really ancient compiler.
but in normal execution it returns true

Better to say: it returns true with some probability. Most likely
probability = 1/256.

Nov 29 '05 #7
>better to say: it returns true with some probability. Most likely probability = 1/256.

The probability is 255/256 since every value different from zero is
interpreted as "true".

Nov 30 '05 #8

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

Similar topics

1
by: Junior | last post by:
I keep receiving this "The type or namespace name 'CASsEventHandler' could not be found (are you missing a using directive or an assembly reference?)" message in two particular lines, and I've...
6
by: David B. Bitton | last post by:
I am having a problem deserializing XML when the root node is missing a namespace declaration. My Type has an XmlTypeAttribute with a namespace defined. If I attempt to deserialize the XML, I get...
2
by: Andrew | last post by:
Hey all, Have a strange one here, and being still fairly new to .NET isn't helping me understand it. I am having a problem where a DataReader doesn't return all the rows when I try to use a...
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 by serveraddresss?wsdl, it gives me following error: Custom tool...
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...
0
by: Joe | last post by:
Hi I have a Typed Dataset (TDS) and am using the derived class. I wrote a wrapper Class around the TDS class to manipulate the class {Add,Delete, return Dataset etc} - All is fine except when I...
11
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
2
by: im2cre8iv | last post by:
Here is my code where I am receiving the error: #include <fstream> #include "BinaryTree.h" using namespace std; Node* BinaryTree::MakeTree(ifstream& infile) { char name; infile>>name;
6
KoreyAusTex
by: KoreyAusTex | last post by:
If anyone can help me figure out the what the missing return statements are, I think it might be the fact that I need to add a return false in the getValue()? import java.util.*; public class...
7
by: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= | last post by:
Hi, I have been using the code (some of it has been removed for simplicity) below to allow authenticated (using ASP.NET membership database) users to get a file from their archive area. It...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.