Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » CGoto page 1, 2  Next

No return in LONG InterlockedDecrement ( LONG *lpAddend )

 
Jump to:  
 
slackcode
PostPosted: Wed Aug 27, 2008 5:22 am    Post subject: No return in LONG InterlockedDecrement ( LONG *lpAddend )
       
I use MiniMFC in Linux. And found the function InterlockedDecrement
don't has the "return xxx":
LONG InterlockedDecrement ( LONG *lpAddend )
{
*lpAddend = *lpAddend - 1;
}

I write a test program like this function, and it return the value of
*lpAddend without the return sentence in the end of the function.
Maybe It return EAX by default, but I'm not sure about that.

CString of MiniMFC use this function like:
void CString::Release()
{
if (GetData() != _afxDataNil)
{
ASSERT(GetData()->nRefs != 0);
if (InterlockedDecrement(&GetData()->nRefs) <= 0)
FreeData(GetData());
Init();
}
}

So the return value of InterlockedDecrement is very important. And I
am not sure the return value and the CString::Release() will occur
some mistagke
 

 
Flash Gordon
PostPosted: Wed Aug 27, 2008 5:22 am    Post subject: Re: No return in LONG InterlockedDecrement ( LONG *lpAddend
       
slackcode wrote, On 27/08/08 06:22:
Quote:
I use MiniMFC in Linux. And found the function InterlockedDecrement
don't has the "return xxx":
LONG InterlockedDecrement ( LONG *lpAddend )
{
*lpAddend = *lpAddend - 1;
}

I write a test program like this function, and it return the value of
*lpAddend without the return sentence in the end of the function.
Maybe It return EAX by default, but I'm not sure about that.

It happened to be somewhere that allowed you to pick it up by chance.
Change something apparently unrelated and that could change. Either make
the function return an appropriate or change the return type of the
function to void. Also see if you can turn up the warning level on your
compiler, some can warn about problems like this.

Quote:
CString of MiniMFC use this function like:
void CString::Release()

<snip>

C++ and C are different languages with separate groups. Since
comp.lang.c++ is next to comp.lang.c in most newsgroup lists I find it
hard to understand how people miss the group and end up posting C++ here.
--
Flash Gordon
 

 
slackcode
PostPosted: Wed Aug 27, 2008 5:23 am    Post subject: Re: No return in LONG InterlockedDecrement ( LONG *lpAddend
       
Sorry!

So the return value of InterlockedDecrement is very important. And I
am not sure the return value and the CString::Release() will occur
some mistake. Could some one can explain that? Thank you very much!

regards,
slackcode
 

 
Ian Collins
PostPosted: Wed Aug 27, 2008 6:13 am    Post subject: Re: No return in LONG InterlockedDecrement ( LONG *lpAddend
       
Nick Keighley wrote:
Quote:
On 27 Aug, 06:22, slackcode <slackc...@gmail.com> wrote:

I use MiniMFC in Linux. And found the function InterlockedDecrement
don't has the "return xxx":
LONG InterlockedDecrement ( LONG *lpAddend )
{
*lpAddend = *lpAddend - 1;

}

that is an error. Or more formally "Undefined Behaviour".
The implementation can do whatever it likes.

Which really should be a constraint violation.


--
Ian Collins.
 

 
Richard Bos
PostPosted: Wed Aug 27, 2008 7:53 am    Post subject: Re: No return in LONG InterlockedDecrement ( LONG *lpAddend
       
Ian Collins <ian-news@hotmail.com> wrote:

Quote:
Nick Keighley wrote:
On 27 Aug, 06:22, slackcode <slackc...@gmail.com> wrote:

I use MiniMFC in Linux. And found the function InterlockedDecrement
don't has the "return xxx":
LONG InterlockedDecrement ( LONG *lpAddend )
{
*lpAddend = *lpAddend - 1;

}

that is an error. Or more formally "Undefined Behaviour".
The implementation can do whatever it likes.

Which really should be a constraint violation.

It can't be; it is possible (with thanks to Gödel and related theorems)
to write a function in which all paths terminate in a return statement,
but the implementation isn't able to prove that.

Richard
 

 
Nick Keighley
PostPosted: Wed Aug 27, 2008 8:02 am    Post subject: Re: No return in LONG InterlockedDecrement ( LONG *lpAddend
       
On 27 Aug, 06:22, slackcode <slackc...@gmail.com> wrote:

Quote:
I use MiniMFC in Linux. And found the function InterlockedDecrement
don't has the "return xxx":
LONG InterlockedDecrement ( LONG *lpAddend )
{
        *lpAddend = *lpAddend - 1;

}

that is an error. Or more formally "Undefined Behaviour".
The implementation can do whatever it likes.


Quote:
I write a test program like this function, and it return the value of
*lpAddend  without the return sentence in the end of the function.

such as that

Quote:
Maybe It return EAX by default, but I'm not sure about that.

CString of MiniMFC use this function like:
void CString::Release()
{
        if (GetData() != _afxDataNil)
        {
                ASSERT(GetData()->nRefs != 0);
                if (InterlockedDecrement(&GetData()->nRefs) <= 0)
                        FreeData(GetData());
                Init();
        }
}

So the return value of InterlockedDecrement is very important. And I
am not sure the return value and the  CString::Release() will occur
some [mistake. can someone explain this?]

you have Undefined Behaviour

--
Nick Keighley

Programming should never be boring, because anything
mundane and repetitive should be done by the computer.
~Alan Turing
 

 
James Kuyper
PostPosted: Wed Aug 27, 2008 8:42 am    Post subject: Re: No return in LONG InterlockedDecrement ( LONG *lpAddend
       
Richard Bos wrote:
Quote:
Ian Collins <ian-news@hotmail.com> wrote:

Nick Keighley wrote:
On 27 Aug, 06:22, slackcode <slackc...@gmail.com> wrote:

I use MiniMFC in Linux. And found the function InterlockedDecrement
don't has the "return xxx":
LONG InterlockedDecrement ( LONG *lpAddend )
{
*lpAddend = *lpAddend - 1;

}
that is an error. Or more formally "Undefined Behaviour".
The implementation can do whatever it likes.

Which really should be a constraint violation.

It can't be; it is possible (with thanks to Gödel and related theorems)
to write a function in which all paths terminate in a return statement,
but the implementation isn't able to prove that.

The standard could make it a constraint violation to leave out return
statements in certain locations, even if the programmer can figure out
that they will never be executed. If "certain locations" is specified
appropriately (which I will not attempt to do), then checking whether
this has been done would become feasible in all cases.

I don't think that this would be popular. Compilers which currently
perform a sufficiently sophisticated check for unreachable code might,
as a QoI issue, have to turn off the corresponding warning in cases
where leaving out the unreachable code would be a constraint violation
under the new rule.
 

 
Willem
PostPosted: Wed Aug 27, 2008 11:48 am    Post subject: Re: No return in LONG InterlockedDecrement ( LONG *lpAddend
       
Ian Collins wrote:
) Nick Keighley wrote:
)> On 27 Aug, 06:22, slackcode <slackc...@gmail.com> wrote:
)>
)>> I use MiniMFC in Linux. And found the function InterlockedDecrement
)>> don't has the "return xxx":
)>> LONG InterlockedDecrement ( LONG *lpAddend )
)>> {
)>> *lpAddend = *lpAddend - 1;
)>>
)>> }
)>
)> that is an error. Or more formally "Undefined Behaviour".
)> The implementation can do whatever it likes.
)>
) Which really should be a constraint violation.

constraint violations are usually restricted to things that can be easily
checked by a compiler. Ensuring that a non-void function always returns a
value requires code path analysis at the very least.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 

 
Andrew Poelstra
PostPosted: Wed Aug 27, 2008 12:25 pm    Post subject: Re: No return in LONG InterlockedDecrement ( LONG *lpAddend
       
On 2008-08-27, Richard Bos <rlb@hoekstra-uitgeverij.nl> wrote:
Quote:
Ian Collins <ian-news@hotmail.com> wrote:

Nick Keighley wrote:
On 27 Aug, 06:22, slackcode <slackc...@gmail.com> wrote:

I use MiniMFC in Linux. And found the function InterlockedDecrement
don't has the "return xxx":
LONG InterlockedDecrement ( LONG *lpAddend )
{
*lpAddend = *lpAddend - 1;

}

that is an error. Or more formally "Undefined Behaviour".
The implementation can do whatever it likes.

Which really should be a constraint violation.

It can't be; it is possible (with thanks to Gödel and related theorems)
to write a function in which all paths terminate in a return statement,
but the implementation isn't able to prove that.


Indeed. C# requires superfluous return statements, and it is a source
of great frustration, since the programmer needs to add a comment saying
that he's being program-illogical to appease the compiler.

--
Andrew Poelstra apoelstra@wpsoftware.com
To email me, use the above email addresss with .com set to .net
 

 
Ian Collins
PostPosted: Wed Aug 27, 2008 5:09 pm    Post subject: Re: No return in LONG InterlockedDecrement ( LONG *lpAddend
       
Willem wrote:
Quote:
Ian Collins wrote:
) Nick Keighley wrote:
)> On 27 Aug, 06:22, slackcode <slackc...@gmail.com> wrote:
)
)>> I use MiniMFC in Linux. And found the function InterlockedDecrement
)>> don't has the "return xxx":
)>> LONG InterlockedDecrement ( LONG *lpAddend )
)>> {
)>> *lpAddend = *lpAddend - 1;
)
)>> }
)
)> that is an error. Or more formally "Undefined Behaviour".
)> The implementation can do whatever it likes.
)
) Which really should be a constraint violation.

constraint violations are usually restricted to things that can be easily
checked by a compiler. Ensuring that a non-void function always returns a
value requires code path analysis at the very least.

Ensuring a non-void function has at least one return statement isn't hard.


--
Ian Collins.
 

Page 1 of 2 .:. Goto page 1, 2  Next

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

forum komputerowe podpis elektroniczny Darmowe Teledyski teksty odzież dla dzieci