Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Eventual undefined behaviour

Reply
Thread Tools

Eventual undefined behaviour

 
 
Thad Smith
Guest
Posts: n/a
 
      09-16-2007
Flash Gordon wrote:
> Spiros Bousbouras wrote, On 15/09/07 14:23:
>> On 15 Sep, 00:47, Flash Gordon <(E-Mail Removed)> wrote:
>>> Note that some processors (the ones I know are DSPs have the ability to
>>> limit at maximum +ve/-ve.

>>
>> What does "ve" mean ? Neither dictionary.com nor
>> acronymfinder.com gave me a definition which makes
>> sense in this context.

>
> +ve is a fairly well known abbreviation for positive in England and I
> suspect a number of other countries. I'll let you work out what -ve is.


I'm guessing that you mean positive voltage, instead of a positive
number. This assumes that the value represents a voltage.

>> outOfTopic {
>> What does it mean for a DSP to "limit" ? I've
>> never seen "limit" being used as an intransitive
>> verb.
>> }


As Keith suggests, "saturates" (v.i.) is a reasonable substitute, but it
doesn't work for the negative case. The straight-forward rewording
would be to limit the value to the range maximum and minimum.

--
Thad
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      09-17-2007
Thad Smith <(E-Mail Removed)> writes:
> Flash Gordon wrote:
>> Spiros Bousbouras wrote, On 15/09/07 14:23:
>>> On 15 Sep, 00:47, Flash Gordon <(E-Mail Removed)> wrote:
>>>> Note that some processors (the ones I know are DSPs have the ability to
>>>> limit at maximum +ve/-ve.
>>>
>>> What does "ve" mean ? Neither dictionary.com nor
>>> acronymfinder.com gave me a definition which makes
>>> sense in this context.

>> +ve is a fairly well known abbreviation for positive in England and
>> I suspect a number of other countries. I'll let you work out what
>> -ve is.

>
> I'm guessing that you mean positive voltage, instead of a positive
> number. This assumes that the value represents a voltage.


Why would you assume that it refers to a voltage? The "ve" comes from
the last two letters of the words "negative" and "positive".

>>> outOfTopic {
>>> What does it mean for a DSP to "limit" ? I've
>>> never seen "limit" being used as an intransitive
>>> verb.
>>> }

>
> As Keith suggests, "saturates" (v.i.) is a reasonable substitute, but
> it doesn't work for the negative case. The straight-forward rewording
> would be to limit the value to the range maximum and minimum.


Flash Gordon can explain what he meant, but it seemed clear enough to
me (though terse): expressions whose results would exceed INT_MAX
yield INT_MAX, and expressions whose results would be less than
INT_MIN yield INT_MIN. I don't see why it doesn't work for the
negative case.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      09-17-2007
Keith Thompson <(E-Mail Removed)> wrote:

> Thad Smith <(E-Mail Removed)> writes:
> > Flash Gordon wrote:
> >> Spiros Bousbouras wrote, On 15/09/07 14:23:
> >>> On 15 Sep, 00:47, Flash Gordon <(E-Mail Removed)> wrote:
> >>>> Note that some processors (the ones I know are DSPs have the ability to
> >>>> limit at maximum +ve/-ve.
> >>>
> >>> What does "ve" mean ? Neither dictionary.com nor
> >>> acronymfinder.com gave me a definition which makes
> >>> sense in this context.
> >> +ve is a fairly well known abbreviation for positive in England and
> >> I suspect a number of other countries. I'll let you work out what
> >> -ve is.

> >
> > I'm guessing that you mean positive voltage, instead of a positive
> > number. This assumes that the value represents a voltage.

>
> Why would you assume that it refers to a voltage? The "ve" comes from
> the last two letters of the words "negative" and "positive".


Because outside electrics, there's really not much need to abbreviate
positive and negative to plussive and minussive.

Richard
 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      09-17-2007
Keith Thompson wrote, On 17/09/07 04:49:
> Thad Smith <(E-Mail Removed)> writes:
>> Flash Gordon wrote:
>>> Spiros Bousbouras wrote, On 15/09/07 14:23:
>>>> On 15 Sep, 00:47, Flash Gordon <(E-Mail Removed)> wrote:
>>>>> Note that some processors (the ones I know are DSPs have the ability to
>>>>> limit at maximum +ve/-ve.
>>>> What does "ve" mean ? Neither dictionary.com nor
>>>> acronymfinder.com gave me a definition which makes
>>>> sense in this context.
>>> +ve is a fairly well known abbreviation for positive in England and
>>> I suspect a number of other countries. I'll let you work out what
>>> -ve is.

>> I'm guessing that you mean positive voltage, instead of a positive
>> number. This assumes that the value represents a voltage.

>
> Why would you assume that it refers to a voltage? The "ve" comes from
> the last two letters of the words "negative" and "positive".


I agree. I'm not even original in using them like that.

>>>> outOfTopic {
>>>> What does it mean for a DSP to "limit" ? I've
>>>> never seen "limit" being used as an intransitive
>>>> verb.
>>>> }

>> As Keith suggests, "saturates" (v.i.) is a reasonable substitute, but
>> it doesn't work for the negative case. The straight-forward rewording
>> would be to limit the value to the range maximum and minimum.

>
> Flash Gordon can explain what he meant, but it seemed clear enough to
> me (though terse): expressions whose results would exceed INT_MAX
> yield INT_MAX, and expressions whose results would be less than
> INT_MIN yield INT_MIN. I don't see why it doesn't work for the
> negative case.


This is indeed what I meant and it is behaviour some DSPs can be set to
because it is very useful behaviour in signal processing.
--
Flash Gordon
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      09-17-2007
Flash Gordon wrote:
> Keith Thompson wrote:
>

.... snip ...
>
>> Flash Gordon can explain what he meant, but it seemed clear enough
>> to me (though terse): expressions whose results would exceed
>> INT_MAX yield INT_MAX, and expressions whose results would be less
>> than INT_MIN yield INT_MIN. I don't see why it doesn't work for
>> the negative case.

>
> This is indeed what I meant and it is behaviour some DSPs can be
> set to because it is very useful behaviour in signal processing.


While it may be useful for SOME input schemes, in general it loses
the ability to detect and correct overflows (note the correct). In
addition, it effectively converts the extreme values into overflow
signals, with no correction available.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      09-17-2007
CBFalconer wrote, On 17/09/07 10:54:
> Flash Gordon wrote:
>> Keith Thompson wrote:
>>

> ... snip ...
>>> Flash Gordon can explain what he meant, but it seemed clear enough
>>> to me (though terse): expressions whose results would exceed
>>> INT_MAX yield INT_MAX, and expressions whose results would be less
>>> than INT_MIN yield INT_MIN. I don't see why it doesn't work for
>>> the negative case.

>> This is indeed what I meant and it is behaviour some DSPs can be
>> set to because it is very useful behaviour in signal processing.

>
> While it may be useful for SOME input schemes, in general it loses
> the ability to detect and correct overflows (note the correct). In
> addition, it effectively converts the extreme values into overflow
> signals, with no correction available.


I did not say it solves every problem only that it is very useful. I did
not even say how often it is very useful, but I will correct that, there
are a lot of situations in which it is very useful. This is why the chip
manufacturers provide this. One typical instance where it is useful is
if you are producing a signal which will be sent to a speaker, limiting
will distort the sound where wrapping is likely to wreck the speaker.
The same applies to any other control system where you will be producing
magnetic fields to deflect something (even an electron beam in a TV),
limiting will give you distorted output where wrapping will wreck
things. Do you want your dolby surround sound processor to wreck your
expensive speakers (and maybe the power amp as well) but come up with a
nice little message, or do you want it to prevent any damage?

The processor *may* also set an overflow flag and so avoid loosing the
information. I can't remember if the processors I used did this or not,
but it could certainly be done.
--
Flash Gordon
 
Reply With Quote
 
Bart van Ingen Schenau
Guest
Posts: n/a
 
      09-17-2007
CBFalconer wrote:

> Flash Gordon wrote:
>> Keith Thompson wrote:
>>

> ... snip ...
>>
>>> Flash Gordon can explain what he meant, but it seemed clear enough
>>> to me (though terse): expressions whose results would exceed
>>> INT_MAX yield INT_MAX, and expressions whose results would be less
>>> than INT_MIN yield INT_MIN. I don't see why it doesn't work for
>>> the negative case.

>>
>> This is indeed what I meant and it is behaviour some DSPs can be
>> set to because it is very useful behaviour in signal processing.

>
> While it may be useful for SOME input schemes, in general it loses
> the ability to detect and correct overflows (note the correct).


I don't see how that behaviour limits your ability to detect and correct
overflows.
Overflowing a signed integer results in UB, so you would have to catch
the possible overflow before it occurs anyway. Or do you advocate the
we should limit our portability to platforms where it is documented
that overflow results in a wrap-around?

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://c-faq.com/
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      09-17-2007
On Mon, 17 Sep 2007 06:36:03 GMT, in comp.lang.c ,
(E-Mail Removed) (Richard Bos) wrote:

>Keith Thompson <(E-Mail Removed)> wrote:
>
>> Why would you assume that it refers to a voltage? The "ve" comes from
>> the last two letters of the words "negative" and "positive".

>
>Because outside electrics, there's really not much need to abbreviate
>positive and negative to plussive and minussive.


Huh? I do it all the time.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      09-17-2007
Flash Gordon wrote:
> CBFalconer wrote, On 17/09/07 10:54:
>> Flash Gordon wrote:
>>> Keith Thompson wrote:
>>>

>> ... snip ...
>>>> Flash Gordon can explain what he meant, but it seemed clear
>>>> enough to me (though terse): expressions whose results would
>>>> exceed INT_MAX yield INT_MAX, and expressions whose results
>>>> would be less than INT_MIN yield INT_MIN. I don't see why
>>>> it doesn't work for the negative case.
>>>
>>> This is indeed what I meant and it is behaviour some DSPs can be
>>> set to because it is very useful behaviour in signal processing.

>>
>> While it may be useful for SOME input schemes, in general it
>> loses the ability to detect and correct overflows (note the
>> correct). In addition, it effectively converts the extreme
>> values into overflow signals, with no correction available.

>

.... snip ...
>
> The processor *may* also set an overflow flag and so avoid
> loosing the information. I can't remember if the processors I
> used did this or not, but it could certainly be done.


The point is that the information to perform the recovery has been
lost once the value overflows to a MAX or a MIN value. Recovery
requires the original operands, which are no longer available. For
addition, overflow with a separate signal and a modulo result
allows addition (or subtraction) of a constant to regain the
correct answer. None of this prevents the whole business being C
std compatible.

None of this is negating anything you said, it is just a factor for
users to keep in mind.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      09-17-2007
Bart van Ingen Schenau wrote:
> CBFalconer wrote:
>> Flash Gordon wrote:
>>> Keith Thompson wrote:
>>>

>> ... snip ...
>>>
>>>> Flash Gordon can explain what he meant, but it seemed clear
>>>> enough to me (though terse): expressions whose results would
>>>> exceed INT_MAX yield INT_MAX, and expressions whose results
>>>> would be less than INT_MIN yield INT_MIN. I don't see why it
>>>> doesn't work for the negative case.
>>>
>>> This is indeed what I meant and it is behaviour some DSPs can be
>>> set to because it is very useful behaviour in signal processing.

>>
>> While it may be useful for SOME input schemes, in general it loses
>> the ability to detect and correct overflows (note the correct).

>
> I don't see how that behaviour limits your ability to detect and
> correct overflows. Overflowing a signed integer results in UB,
> so you would have to catch the possible overflow before it occurs
> anyway. Or do you advocate the we should limit our portability to
> platforms where it is documented that overflow results in a
> wrap-around?


For an example, take the following code, which returns a correct
value at all times for +ve inputs, but does the relatively rapid
int addition rather than long addition (most of the time). The
code ASSUMES modulo overload action and that LONG_MAX > INT_MAX. I
am NOT recommending using this code.

long add(int a, int b) { /* not portable */
int c

c = a + b;
if ((c < a) || (c < b)) /* overflow detected */
return (long)a + (long)b;
else return c;
} /* NOT RECOMMENDED CODE */

Also see my reply to Flash Gordon.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

 
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
The eventual end of crappy lithium batteries? RichA Digital Photography 36 10-31-2009 05:32 AM
typeof x == 'undefined' or x == undefined? -Lost Javascript 13 01-31-2007 12:04 AM
undefined vs. undefined (was: new Array() vs []) VK Javascript 45 09-12-2006 05:26 PM
undefined behavior or not undefined behavior? That is the question Mantorok Redgormor C Programming 70 02-17-2004 02:46 PM
undefined behaviour Dan Cernat C++ 1 11-11-2003 04:49 PM



Advertisments