[comp.lang.c++] "Signed" Implemented Yet?

jima@hplsla.HP.COM (Jim Adcock) (07/11/89)

Is "signed" implemented on any compilers yet?  Isn't this necessary to
guarantee proper working of "signed char" as a tiny int? [I have a class
that could use lots of tiny ints]

#include <stdio.h>

main()
{
  signed char sc = -1;
  unsigned char uc = -1;
  char c = -1;
  signed short ss = -1;
  unsigned short us = -1;
  short s = -1;

  printf("%x %x %x\n",sc,uc,c);
  printf("%x %x %x\n",ss,us,s);
}

bright@Data-IO.COM (Walter Bright) (07/13/89)

In article <6590193@hplsla.HP.COM> jima@hplsla.HP.COM (Jim Adcock) writes:
<Is "signed" implemented on any compilers yet?  Isn't this necessary to
<guarantee proper working of "signed char" as a tiny int? [I have a class
<that could use lots of tiny ints]

As it turns out, nearly all compilers that *don't* support the signed
keyword have chars signed by default. So, use 'signed char' whenever
your char must be signed. For compilers that don't support signed,

	#if ARCHAIC_C
	printf("Complain to your vendor.\n");
	#define signed
	#endif

Interestingly, all current C compilers on MS-DOS that I'm familiar with
support 'signed'.

jima@hplsla.HP.COM (Jim Adcock) (07/13/89)

>Interestingly, all current C compilers on MS-DOS that I'm familiar with
>support 'signed'.

Interestingly, my recent-generation C++ compiler doesn't -- unless that's 
been fixed.  Seems like a shame to have a C++ front end that doesn't understand
"signed" when *all* the C backends do understand it.  I was hoping that some
C++ vendors might speak up about what C++ compilers support it and which don't.
[and why not]

turk@Apple.COM (Ken "Turk" Turkowski) (08/13/89)

In article <6590195@hplsla.HP.COM> jima@hplsla.HP.COM (Jim Adcock) writes:
>>Interestingly, all current C compilers on MS-DOS that I'm familiar with
>>support 'signed'.
>
>Interestingly, my recent-generation C++ compiler doesn't -- unless that's 
>been fixed.  Seems like a shame to have a C++ front end that doesn't understand
>"signed" when *all* the C backends do understand it.  I was hoping that some
>C++ vendors might speak up about what C++ compilers support it and which don't.
>[and why not]

Yes, and this poses severe problems on the IRIS, which has chars as unsigned
by default.  There seems to be no way to get signed chars.
-- 
Ken Turkowski @ Apple Computer, Inc., Cupertino, CA
Internet: turk@apple.com
Applelink: TURKOWSKI1
UUCP: sun!apple!turk

ciemo@bananapc.wpd.sgi.com (Dave Ciemiewicz) (09/12/89)

In article <3520@internal.Apple.COM>, turk@Apple.COM (Ken "Turk" Turkowski) writes:
> In article <6590195@hplsla.HP.COM> jima@hplsla.HP.COM (Jim Adcock) writes:
> >>Interestingly, all current C compilers on MS-DOS that I'm familiar with
> >>support 'signed'.
> >
> >Interestingly, my recent-generation C++ compiler doesn't -- unless that's 
> >been fixed.  Seems like a shame to have a C++ front end that doesn't understand
> >"signed" when *all* the C backends do understand it.  I was hoping that some
> >C++ vendors might speak up about what C++ compilers support it and which don't.
> >[and why not]
> 
> Yes, and this poses severe problems on the IRIS, which has chars as unsigned
> by default.  There seems to be no way to get signed chars.

The C compiler has a flag for defaulting to signed integers (-signed).
If you have a c++ compiler from AT&T, you should be able to pass the -signed
flag on the CC command line to get cc to compile your code with default
signed integers.

This is the case with the C++ product from Silicon Graphics which should
be released in the very near future.

						--- Dave

--
-------------------------------------------------------------------------------
			Cosmo Ciemo, Silicon Valley Dude

I was traipsing through the fields of my mind when I stepped in something that
smelled rather ripe.
-------------------------------------------------------------------------------

jima@hplsla.HP.COM (Jim Adcock) (09/13/89)

This solution is probably specific to Silicon Graphics.  When I try it
on my HP CC 2.0 series300 implementation, I get:

% CC -signed signed.c

CC signed.c:
"signed.c", line 5: warning: " signed" not implemented (ignored)
cc -signed signed.i -lC
cc: (warning) unrecognized option -i
cc: (warning) unrecognized option -e
cc: (warning) unrecognized option -d
cc: (warning) unrecognized option -i
cc: (warning) unrecognized option -e
cc: (warning) unrecognized option -d
cc: (warning) unrecognized option -i
cc: (warning) unrecognized option -e
cc: (warning) unrecognized option -d

ld: interrupt
ld: (Warning) did not generate an output file

...where signed.c is:

#include <stdio.h>

void main()
{
  signed char c = -10;
  printf("%d\n",c);
}

On this machine, apparently CC rejects the "signed" keyword, replacing it
with null, generates an unnecessary warning message, then passes the 
equivalent "C" code to the backend compiler, which has "signed" chars
by default, and thus [in this case at least] actually generates what was
called for.  End score: 0 compilation errors, 1 erroneous warning message.

ciemo@bananapc.wpd.sgi.com (Dave Ciemiewicz) (09/13/89)

In article <41603@sgi.sgi.com>, ciemo@bananapc.wpd.sgi.com (Dave Ciemiewicz) writes:
> In article <3520@internal.Apple.COM>, turk@Apple.COM (Ken "Turk" Turkowski) writes:
> > Yes, and this poses severe problems on the IRIS, which has chars as unsigned
> > by default.  There seems to be no way to get signed chars.
> 
> The C compiler has a flag for defaulting to signed integers (-signed).
						     ^^^^^^^^
						     chars

Ahem, I meant to say that the -signed flag for the C compiler causes the
compiler to default to signed chars instead of unsigned chars.  If you are
used to programming in environments with signed chars as the default, you
can use this flag with your C++ compiler (CC should pass it through to
the C compiler.).

						--- Dave
--
-------------------------------------------------------------------------------
			Cosmo Ciemo, Silicon Valley Dude

I was traipsing through the fields of my mind when I stepped in something that
smelled rather ripe.
-------------------------------------------------------------------------------