data type for decimal number

R

Richard Heathfield

Harald van D?k said:
Keith Thompson said:

4.9.6.1 of C89:

d, i, o, u, x, X The int argument is converted to signed decimal ( d
or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
hexadecimal notation ( x or X );

Sure looks like int to me.

Interesting. C99 7.19.6.1p8:

o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or X)
in the style /dddd/; [...]

Hmmm. Okay, so that's (perhaps) Yet Another Difference between C89 and C99
- and a potentially significant one, since it causes difficulty for those
wishing to program in the common subset of the two languages. I say
"perhaps" because my source doc for C89 is (pace, C.H.!) a mere draft, and
as such is suspect in cases like this. Does anyone have a kosher copy of
the "real" C89 in which they could check this out?
 
Y

ymuntyan

Keith Thompson said:
4.9.6.1 of C89:
d, i, o, u, x, X The int argument is converted to signed decimal ( d
or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
hexadecimal notation ( x or X );
Sure looks like int to me.

Interesting. C99 7.19.6.1p8:

o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or X)
in the style /dddd/; [...]

ANSI/ISO 9899-1990
American National Standard for Programming Languages - C

7.9.6.1 The fprintf function

o, u, , x, X The unsigned int argument...
 
R

Richard Tobin

Richard Heathfield said:
Hmmm. Okay, so that's (perhaps) Yet Another Difference between C89 and C99
- and a potentially significant one, since it causes difficulty for those
wishing to program in the common subset of the two languages. I say
"perhaps" because my source doc for C89 is (pace, C.H.!) a mere draft, and
as such is suspect in cases like this. Does anyone have a kosher copy of
the "real" C89 in which they could check this out?

My copies of C89 (which are BSI standard BS EN 29899:1993, and the BSI
copy of the ISO draft copied from ANSI distributed in 1989-90 for
comments), both specify unsigned int for o,u,x,X. A 1984 draft has
wording similar to yours.

-- Richard
 
Y

ymuntyan

W

Walter Roberson

Harald van D?k said:
Keith Thompson said:
Actually, %x takes an int, not a hex. C doesn't have a hex type.
Actually, %x takes an unsigned int.
4.9.6.1 of C89:
d, i, o, u, x, X The int argument is converted to signed decimal ( d
or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
hexadecimal notation ( x or X );
Sure looks like int to me.
Interesting. C99 7.19.6.1p8:
o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or X)
in the style /dddd/; [...]
Hmmm. Okay, so that's (perhaps) Yet Another Difference between C89 and C99
- and a potentially significant one, since it causes difficulty for those
wishing to program in the common subset of the two languages. I say
"perhaps" because my source doc for C89 is (pace, C.H.!) a mere draft, and
as such is suspect in cases like this. Does anyone have a kosher copy of
the "real" C89 in which they could check this out?

I have the official ANSI C89 hard-copy publication. It describes
the integer formats in two related paragraphs, the first of which
is a summary for all of the formats and uses "int", and the second
of which is specific to o,u,x,X and uses "unsigned int".

I consider the second of the paragraphs to be a refinement of the first,
with the first giving the overview and the second the specifics. Thus
I see no contradiction between versions: as far as I am concerned, both
C89 and C99 specify that %x and %X require unsigned int.
 
B

Ben Pfaff

Another interesting thing:
http://www.lysator.liu.se/c/rat/d9.html#4-9-6-1
What the heck?

I assume that you are talking about this paragraph at the cited
URL:

Note that the %X and %x formats expect a corresponding int
argument; %lX or %lx must be supplied with a long int
argument.

This was corrected in the corresponding paragraph of the C99
rationale:

Note that the %X and %x formats expect a corresponding
unsigned int argument, and %lX and %lx must be supplied
with an unsigned long argument.

So I assume that it was simply a mistake.
 
Y

ymuntyan

Harald van D?k said:
Actually, %x takes an int, not a hex. C doesn't have a hex type.
Actually, %x takes an unsigned int.
4.9.6.1 of C89:
d, i, o, u, x, X The int argument is converted to signed decimal ( d
or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
hexadecimal notation ( x or X );
Sure looks like int to me.
Interesting. C99 7.19.6.1p8:
o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or X)
in the style /dddd/; [...]
Hmmm. Okay, so that's (perhaps) Yet Another Difference between C89 and C99
- and a potentially significant one, since it causes difficulty for those
wishing to program in the common subset of the two languages. I say
"perhaps" because my source doc for C89 is (pace, C.H.!) a mere draft, and
as such is suspect in cases like this. Does anyone have a kosher copy of
the "real" C89 in which they could check this out?

I have the official ANSI C89 hard-copy publication. It describes
the integer formats in two related paragraphs, the first of which
is a summary for all of the formats and uses "int", and the second
of which is specific to o,u,x,X and uses "unsigned int".

So this means that the ISO standard was actually different from
the ANSI one (because the ISO one has two paragraphs, one for 'i,d',
and another one for 'o,u,x,X')? Is there a list of changes somewhere?

Yevgen
 
R

Richard Heathfield

Walter Roberson said:

I have the official ANSI C89 hard-copy publication. It describes
the integer formats in two related paragraphs, the first of which
is a summary for all of the formats and uses "int", and the second
of which is specific to o,u,x,X and uses "unsigned int".

I consider the second of the paragraphs to be a refinement of the first,
with the first giving the overview and the second the specifics. Thus
I see no contradiction between versions: as far as I am concerned, both
C89 and C99 specify that %x and %X require unsigned int.

Thank you, Walter. I have amended my C89 draft accordingly (because
otherwise I'll only make the same stupid mistake again!).

And, of course, my apologies to all, for posting misleading information
upthread.
 
L

lawrence.jones

Walter Roberson said:
I have the official ANSI C89 hard-copy publication. It describes
the integer formats in two related paragraphs, the first of which
is a summary for all of the formats and uses "int", and the second
of which is specific to o,u,x,X and uses "unsigned int".

That's interesting, *my* nearly-official copy (what was sent to ANSI for
publication) matches ANSI/ISO C90: the first paragraph is for "d" and
"i" and says "int", the second paragraph is for "o", "u", "x", and "X"
and says "unsigned int". Are you sure you're not misreading it? I
sincerely doubt that ANSI change the camera-ready copy.

-Larry Jones

You know how Einstein got bad grades as a kid? Well MINE are even WORSE!
-- Calvin
 
K

Keith Thompson

Mark Bluemel said:
Is this the Schroedinger C compiler we're talking about here?

Yes and no.

What I meant is that unsigned long is very often the same size as void*.
 
K

Keith Thompson

Harald van D?k said:
Actually, %x takes an int, not a hex. C doesn't have a hex type.
Actually, %x takes an unsigned int.
4.9.6.1 of C89:
d, i, o, u, x, X The int argument is converted to signed decimal ( d
or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
hexadecimal notation ( x or X );
Sure looks like int to me.
Interesting. C99 7.19.6.1p8:
o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or X)
in the style /dddd/; [...]
Hmmm. Okay, so that's (perhaps) Yet Another Difference between C89 and C99
- and a potentially significant one, since it causes difficulty for those
wishing to program in the common subset of the two languages. I say
"perhaps" because my source doc for C89 is (pace, C.H.!) a mere draft, and
as such is suspect in cases like this. Does anyone have a kosher copy of
the "real" C89 in which they could check this out?

I have the official ANSI C89 hard-copy publication. It describes
the integer formats in two related paragraphs, the first of which
is a summary for all of the formats and uses "int", and the second
of which is specific to o,u,x,X and uses "unsigned int".

I consider the second of the paragraphs to be a refinement of the first,
with the first giving the overview and the second the specifics. Thus
I see no contradiction between versions: as far as I am concerned, both
C89 and C99 specify that %x and %X require unsigned int.

I have the official ISO C90 PDF publication. Here's what it says:

d,i The int argument is converted to signed decimal in the style
(-]dddd. The precision specifies the minimum number of digits
to appear, if the value being converted can be represented in
fewer digits, it will be expanded with leading zeros. The
default precision is 1. The result of converting a zero value
with a precision of zero is no characters.

o,u,x,X The unsigned int argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or
X) in the style dddd, the letters abcdef are used for x
conversion and the letters ABCDEF for X conversion. The
precision specifies the minimum number of digits to appear; if
the value being converted can be represented in fewer digits,
it will be expanded with leading zeros. The default precision
is 1. The result of converting a zero value with a precision
of zero is no characters.

(It's not a good PDF copy; there may be typos in the above.)

Does that not match the ANSI C89 standard?
 
M

Martin

W

Walter Roberson

Richard Heathfield said:
4.9.6.1 of C89:

d, i, o, u, x, X The int argument is converted to signed decimal ( d
or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
hexadecimal notation ( x or X );
Sure looks like int to me.

Extracting the relevant paragraphs of C89 4.9.6.1, starting from
page 133 of the hardcopy (X3.159-1989)

==== page 133 ====

o An option precision gives the minimum number of digits to appear
for the d, i, o, u, x, and X conversions, the number of digits
to appear after the decimal-point character for e, E, and f
conversions, the maximum number of significant digits for the
g and G conversions, or the maximum number of characters to
be written from a string in s conversion. The precision takes
the form of a period (.) followed either by an asterisk *
(described later) or by an option decimal integer; if only the
period is specified, the precision is taken as zero. If the
precision appears with any other conversion specifier, the
behavior is undefined.

o An optional h specifiing that the following d, i, o, u, x, or X
conversion specifier applies to a short int or unsigned short int
argument (the argument will have been promoted according
to the integral promotions, and its value shall be converted to
short int or unsigned short int before printing); an optional h
specifying that a following n conversion specifier applies to
a pointer to a short in argument; an optional l (ell)
specifying that the following d, i, o, u, x, or X conversion
specifier applies to a long int or unsigned long int argument;
an optional l specifying that a following n conversion specifier
applies to a poiner to a long int argument; or an optional L
specifying that a following e, E, f, g, or G conversion specifier
applies to a long double argument. If an h, l or L appears
with any other conversion specifier, the behavior is undefined.
[...]
The flag characters and their meanings are
[...]
# The result is to be converted to an "alternate form". For o
conversions, it increases the precision to force the first digit
of the result to be a zero. For x (or X) conversion, a
nonzero result with have 0x (or 0X) prefixed to it. For
e, E, f, g, and G conversion, the result will always contain
a decimal-point character, even if no digits follow it.
(Normally, a decimal-point character appears in the result of
these conversions only if a digit follows it.) For g and G
conversions, trailing zeros will not be removed from the
result. For other conversions, the behavior is undefined.

==== page 134 ====
0 For d, i, o, u, x, X, e, E, f, g, and G conversions, leading zeros
(following any indication of sign or base) are used to pad to
the field width; no space padding is performed. If the 0 and -
flags both appear, the 0 flag will be ignored. For d, i, o, u,
x, and X conversions, if a precision is specified, the 0 flag
will be ignored. For other conversions, the behavior is undefined.

The conversion specifiers and their meanings are

d,i The int argument is converted to signed decimal in the style
[-]dddd. The precision specifies the minimum number of digits
to appear; if the value being converted can be represented in
fewer digits, it will be expanding with leading zeros. The
default precision is 1. The result of converting a zero value with
a precision of zero is no characters.

o,u,x,X The unsigned int argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or X)
in the style dddd; the letters abcdef are used for x conversion
and the letters ABCDEF for X conversion. The precision specifies
the minimum number of digits to appear; if the value being
converted can be represented in fewer digits, it will be expanded
with leading zeros. The default precision is 1. The result of
converting a zero value with a precision of zero is no characters.

c The int argument is converted to an unsigned char, and the
resulting character is written.


====
The text quoted by Richard Heathfield does NOT appear in
C89 4.9.6.1 in the hardcopy version. (I do not know what his source
was.)
 
W

Walter Roberson

This was corrected in the corresponding paragraph of
the C99 rationale: [...]
This is all rather unfortunate. K&R2, Plauger, http://flash-gordon.me.uk/ans=
i.c.txt
and http://www.lysator.liu.se/c/rat/d9.html#4-9-6-1 all say int is
used for o, u, x, X, yet the definitive resource (ISO/IEC 9899:1990)
says they expect unsigned int, and it's a resource I can't get hold of
- I have to rely on quotes on this Newsgroup.

I could scan the fprintf section from my ANSI X3.159-1989 (C89)
hardcopy and email that to you, if that would be more reassuring
than quotes in the newsgroup. (The relevant pages are already
fallen out of the binding so putting them flat in my scanner would
not be any difficulty.)
 
R

Richard Heathfield

Walter Roberson said:
Extracting the relevant paragraphs of C89 4.9.6.1, starting from
page 133 of the hardcopy (X3.159-1989)

Er, Walter, this is weeks old, if not months.
====
The text quoted by Richard Heathfield does NOT appear in
C89 4.9.6.1 in the hardcopy version.

So I understand.
(I do not know what his source was.)

A draft copy of C89. (I have a "real" C99 Standard, but not C89.)
 
W

Walter Roberson

Walter Roberson said:
Er, Walter, this is weeks old, if not months.

February 18th actually. But someone responded today (or last night)
in the thread, and when I went back up the chain I could see there
was still confusion about where exactly the unsigned had appeared,
with the follow-up postings appearing to indicate that the change
appeared in the Rationale for C99, whereas they were in C89 to start with.
So I quoted everything relevant to (hopefully) settle the matter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top