Unix Technical Forum

Re: char signed or unsinged ? (was Netscape 7 issues)

This is a discussion on Re: char signed or unsinged ? (was Netscape 7 issues) within the AIX Operating System forums, part of the Unix Operating Systems category; --> "Dr. David Kirkby" wrote: > char foo; > > is asking for trouble, if you hope to put negative ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-04-2008, 07:49 PM
Erik Max Francis
 
Posts: n/a
Default Re: char signed or unsinged ? (was Netscape 7 issues)

"Dr. David Kirkby" wrote:

> char foo;
>
> is asking for trouble, if you hope to put negative numbers in foo.


Indeed. The Standard leaves it unspecified whether an unadorned char is
signed or unsigned.

--
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ You win the victory when you yield to friends.
\__/ Sophocles
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-04-2008, 07:49 PM
Dr. David Kirkby
 
Posts: n/a
Default Re: char signed or unsinged ? (was Netscape 7 issues)

Erik Max Francis wrote:
>
> "Dr. David Kirkby" wrote:
>
> > char foo;
> >
> > is asking for trouble, if you hope to put negative numbers in foo.

>
> Indeed. The Standard leaves it unspecified whether an unadorned char is
> signed or unsigned.


I've just confirmed that AIX and IRIX declare it unsigned, whereas
Solaris, Linux, AIX, HP-UX, Tru64, NetBSD, OpenBSD all declare it
signed. Although I've not had chance to fix the problem yet, I think
that explains why my program for computing the properties of
transmission lines
http://atlc.sourceforge.net/
works on Solaris, Linux, AIX, HP-UX, Tru64, NetBSD, OpenBSD, but not
on AIX or IRIX.

At least fixing it should not be too hard - just needs a bit of time.
--
Dr. David Kirkby,
Senior Research Fellow,
Department of Medical Physics,
University College London,
11-20 Capper St, London, WC1E 6JA.
Tel: 020 7679 6408 Fax: 020 7679 6269
Internal telephone: ext 46408
e-mail davek@medphys.ucl.ac.uk
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-04-2008, 07:49 PM
Dr. David Kirkby
 
Posts: n/a
Default Re: char signed or unsinged ? (was Netscape 7 issues)

"Dr. David Kirkby" wrote:

> I've just confirmed that AIX and IRIX declare it unsigned, whereas
> Solaris, Linux, AIX, HP-UX, Tru64, NetBSD, OpenBSD all declare it
> signed.


Sorry, AIX considers it unsigned.
--
Dr. David Kirkby,
Senior Research Fellow,
Department of Medical Physics,
University College London,
11-20 Capper St, London, WC1E 6JA.
Tel: 020 7679 6408 Fax: 020 7679 6269
Internal telephone: ext 46408
e-mail davek@medphys.ucl.ac.uk
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-04-2008, 07:49 PM
Barry Margolin
 
Posts: n/a
Default Re: char signed or unsinged ? (was Netscape 7 issues)

In article <3F14007C.92A259E7@marconi.com>,
John Howells <John.Howells@marconi.com> wrote:
>"Dr. David Kirkby" wrote:
>> Sorry, AIX considers it unsigned.

>
>You have to be careful in saying that, as in principle it is the
>compiler that matters, not the platform. It might be unwise to break the
>platform convention, but in theory one compiler might use signed and one
>unsigned on the same platform.


I would expect this to be treated as part of the platform's ABI, which all
compilers for the platform should conform to. This is because the OS
vendor provides header files for their system call and runtime libraries,
and all hell would break loose if these headers were interpreted
differently by different compilers.

--
Barry Margolin, barry.margolin@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-04-2008, 07:50 PM
Ulrich Weigand
 
Posts: n/a
Default Re: char signed or unsinged ? (was Netscape 7 issues)

"Dr. David Kirkby" <drkirkby@ntlworld.com> writes:

>I've just confirmed that AIX and IRIX declare it unsigned, whereas
>Solaris, Linux, AIX, HP-UX, Tru64, NetBSD, OpenBSD all declare it
>signed.


At least in the case of Linux, it depends very much on the
platform: GCC on Linux defaults to signed char e.g. on i386,
ia64, alpha, sparc, mips, but to unsigned char e.g. on powerpc,
s390, arm ...

--
Dr. Ulrich Weigand
weigand@informatik.uni-erlangen.de
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-04-2008, 07:50 PM
Erik Max Francis
 
Posts: n/a
Default Re: char signed or unsinged ? (was Netscape 7 issues)

"Dr. David Kirkby" wrote:

> I've just confirmed that AIX and IRIX declare it unsigned, whereas
> Solaris, Linux, AIX, HP-UX, Tru64, NetBSD, OpenBSD all declare it
> signed.


The point is, the standard declares it implementation defined. Thus if
you ever need it to be either signed or unsigned, using an andorned char
is a programming error.

--
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Nine worlds I remember.
\__/ Icelandic Edda of Snorri Sturluson
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-04-2008, 07:50 PM
Erik Max Francis
 
Posts: n/a
Default Re: char signed or unsinged ? (was Netscape 7 issues)

John Howells wrote:

> You have to be careful in saying that, as in principle it is the
> compiler that matters, not the platform. It might be unwise to break
> the
> platform convention, but in theory one compiler might use signed and
> one
> unsigned on the same platform.


Or, indeed, signed in one _version_ and unsigned in the next! That
would be particularly obtuse, but there's nothing in the Standard
preventing it.

The point here is that if you need some guarantee and the Standard
doesn't make it, don't look surprised when you get screwed.

--
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Nine worlds I remember.
\__/ Icelandic Edda of Snorri Sturluson
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-04-2008, 07:53 PM
Josef Walzer
 
Posts: n/a
Default Re: char signed or unsinged ? (was Netscape 7 issues)

"Dr. David Kirkby" schrieb:
>
> > I've just confirmed that AIX and IRIX declare it unsigned, whereas
> > Solaris, Linux, AIX, HP-UX, Tru64, NetBSD, OpenBSD all declare it
> > signed.

>
> Sorry, AIX considers it unsigned.

As nobody seems to have mentioned it, this is just a default.
You may change it by adding "-qchars=signed" to the options in /etc/xlC.cfg.

HTH,
Joe

--
Josef Walzer
Messerli Informatik GmbH, Hamoderstr. 4, A-4020 Linz
http:://www.messerli.at
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-04-2008, 07:55 PM
Dr. David Kirkby
 
Posts: n/a
Default Re: char signed or unsinged ? (was Netscape 7 issues)

Josef Walzer wrote:
>
> "Dr. David Kirkby" schrieb:
> >
> > > I've just confirmed that AIX and IRIX declare it unsigned, whereas
> > > Solaris, Linux, AIX, HP-UX, Tru64, NetBSD, OpenBSD all declare it
> > > signed.

> >
> > Sorry, AIX considers it unsigned.

> As nobody seems to have mentioned it, this is just a default.
> You may change it by adding "-qchars=signed" to the options in /etc/xlC.cfg.
>
> HTH,
> Joe

Thanks, but it was basically a bit of dodgy programming on my part to
write a program that needed a signed char, but did not explisitly
state it. Having to configure the compiler is okay if you know the
problem, but is hardly a very good way to distribute code. Hence I've
changed the code.


--
Dr. David Kirkby,
Senior Research Fellow,
Department of Medical Physics,
University College London,
11-20 Capper St, London, WC1E 6JA.
Tel: 020 7679 6408 Fax: 020 7679 6269
Internal telephone: ext 46408
e-mail davek@medphys.ucl.ac.uk
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:32 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com