Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > No return in LONG InterlockedDecrement ( LONG *lpAddend )

Reply
Thread Tools

No return in LONG InterlockedDecrement ( LONG *lpAddend )

 
 
slackcode
Guest
Posts: n/a
 
      08-27-2008
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

 
Reply With Quote
 
 
 
 
slackcode
Guest
Posts: n/a
 
      08-27-2008
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
 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      08-27-2008
slackcode wrote, On 27/08/08 06:22:
> 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.

> 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
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      08-27-2008
On 27 Aug, 06:22, slackcode <(E-Mail Removed)> 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.


> 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

> 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

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      08-27-2008
Nick Keighley wrote:
> On 27 Aug, 06:22, slackcode <(E-Mail Removed)> 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.
 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      08-27-2008
Ian Collins <(E-Mail Removed)> wrote:

> Nick Keighley wrote:
> > On 27 Aug, 06:22, slackcode <(E-Mail Removed)> 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
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      08-27-2008
Richard Bos wrote:
> Ian Collins <(E-Mail Removed)> wrote:
>
>> Nick Keighley wrote:
>>> On 27 Aug, 06:22, slackcode <(E-Mail Removed)> 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.
 
Reply With Quote
 
Willem
Guest
Posts: n/a
 
      08-27-2008
Ian Collins wrote:
) Nick Keighley wrote:
)> On 27 Aug, 06:22, slackcode <(E-Mail Removed)> 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
 
Reply With Quote
 
Andrew Poelstra
Guest
Posts: n/a
 
      08-27-2008
On 2008-08-27, Richard Bos <(E-Mail Removed)> wrote:
> Ian Collins <(E-Mail Removed)> wrote:
>
>> Nick Keighley wrote:
>> > On 27 Aug, 06:22, slackcode <(E-Mail Removed)> 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 http://www.velocityreviews.com/forums/(E-Mail Removed)
To email me, use the above email addresss with .com set to .net
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      08-27-2008
Willem wrote:
> Ian Collins wrote:
> ) Nick Keighley wrote:
> )> On 27 Aug, 06:22, slackcode <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having compilation error: no match for call to ‘(const __gnu_cxx::hash<long long int>) (const long long int&)’ veryhotsausage C++ 1 07-04-2008 05:41 PM
long long and long Mathieu Dutour C Programming 4 07-24-2007 11:15 AM
unsigned long long int to long double Daniel Rudy C Programming 5 09-20-2005 02:37 AM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
Assigning unsigned long to unsigned long long George Marsaglia C Programming 1 07-08-2003 05:16 PM



Advertisments