This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: x86-64 support for gas part I


Geoff Keating <geoffk@geoffk.org> wrote:

> I believe that _hexadecimal_ constants are always unsigned in K&R.  It is
> decimal constants where the behaviour differs between K&R and ANSI
> (because in ANSI, they can be unsigned, but in K&R they aren't).
>
> [I'm just repeating what I've been told, we had a discussion about
> this with respect to -Wtraditional for GCC.]

Rather than believing and repeating what you've been told, how about checking
the spec? "The C Programming Language - Reference Manual"
(ps1/01.Clang/Clang.ms in 4.3BSD docs) says:

: A decimal constant whose value exceeds the largest
: signed machine integer is taken to be
: \fBlong\fR;
: an octal or hex constant which exceeds the largest unsigned machine integer
: is likewise taken to be
: .B
: long\fR.
: .R
: Otherwise, integer constants are \fBint\fR.

All constants are signed regardless of size or radix. While the radix affects
when a constant becomes long, the final type is always either int or long,
never unsigned int or unsigned long.

The different treatment of decimal vs. octal and hex constants for deciding
when to make it long is just for convenience. When writing a decimal constant,
one can directly convey the intended value and sign. Knowing that the result
will always be signed, if the programmer wants to get an int with value -1,
s/he will write -1, not 65535, and if s/he writes 65535, s/he definitely meant
a long with that decimal value. However, a programmer can be reasonably
expected to express an int with value -1 in octal as 0177777 or in hex as
0xFFFF, but as long as it fits in 16 bits, it's still an int and not a long.

--
Michael Sokolov
Public Service Agent
International Engineering and Science Task Force

1351 VINE AVE APT 27		Phone: +1-714-738-5409
FULLERTON CA 92833-4291 USA	(home office)

E-mail: msokolov@ivan.Harhan.ORG (ARPA TCP/SMTP)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]