Re: Signed <-> Unsigned conversions.

John Kelly <j...@xxxxxxxxxxxx> wrote:
Charles Sullivan <cwsul...@xxxxxxxxxxxx> wrote:
Is there a C standard for how conversions between signed
and unsigned variables of the same size are implemented.
 E.g., if I have:

 signed   int  s1, s2;
 unsigned int  u1;

 s1 = -100;
 u1 = s1;

at this point u1 = 4294967196

If, and only if UINT_MAX is 4294967295.

 s2 = u1;

which cannot be represented in s2.  Now if you believe
in standards, C99 say:

Otherwise, the new type is signed and the value cannot be
represented in it; either the result is implementation-
defined or an implementation-defined signal is raised.

Please stop quoting non-posted text with > as if it was written
by a previous poster.


"Otherwise, the new type is signed and the value cannot be
represented in it; either the result is implementation-
defined or an implementation-defined signal is raised."

So your program may freak out, or it may give you a
reasonable answer, depending on your compiler

Any implementation-defined result is reasonable since
it was presumably reasonable for compiler writers to
implement it that way.

But you could mention that by far the most common
conversion doesn't involve signals and simply performs
the inverse conversion of signed to unsigned.

 printf("s2 = %d\n", s2);

With my (gcc) compiler, s2 has the same value (-100) as
s1, but I'm wondering if that's a C standard.

It's highly likely on implementations you're ever likely to
see, but it isn't guaranteed. There are still some sign-
magnitude DSP chipsets being designed where the conversion
of unsigned to signed may not be what you might expect.

I'm still waiting for someone to point out an
implementation that raises a signal in this case.

Wait away. You and I may never see one in our lifetimes.
But the fact that a group of people put their money where
their mouth was, personally paying to be 'volunteers' on
the Committee to put this change in place, suggests they
had at least one such actual implementation in mind.

Even without knowing what that implementation is, I dare
you say you're not quite so stunned to know that floating
point signals are not at all uncommon. There have been
implementations of high ranked integers using floating
point representations.

In order to preserve the congruency between signed and
unsigned value bits, it may well be necessary to use a
non-normalised or biased mantissa. I wouldn't find it at
all suprising for such an implementation to raise a
signal rather than go out of its (already convoluted)
way to avoid one.


Relevant Pages

  • Re: DVD dead!
    ... >>Actually the pits won't be the same length as they are just ... >>representations of a clipped FM signal. ... Look at the way the FM signals are encoded. ... vary in direct proportion to the original signal. ...
  • Re: Representation (without taxation)
    ... (helloooo helloooo helloooo helloooo...) ... everything (or at least everything we refer to loosely as "causation") is ... B signals the possibility of A. In that sense, they are representations ...
  • Re: dvi to hdmi
    ... stays digital from video card memory all the way to the display. ... VGA is first converted to analogue signals, ... with the analogue conversion there happening inside the video ... Screens often have the option ...
  • Re: FCC ordered to stand-down, Eduardo!
    ... radio licensing, spectrum utilization etc. Write to Senator Rockefeller and Representative Waxman and urge them to initiate reassessment of forced conversion to digital TV in a time when most of us barely can afford groceries, ... Some are available for 40 bucks and thus will cost you nothing, or Radio Shack has a couple of nice converters for 50 bucks -- you only pay the $10 difference after using your $40 free coupon, barely more than the cost of a fast food lunch. ... The signal levels at which "acceptable" analog signals can be received will not work for digital. ...
  • Re: AGC signal/noise question...
    ... Dual conversion for HF and triple conversion of 2m. ... limiting so agc is behavour is different. ... van the overall gain change be achieved with fewest control points. ... filter the signals used while using the best techniques. ...