Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > data type for decimal number

Reply
Thread Tools

data type for decimal number

 
 
Keith Thompson
Guest
Posts: n/a
 
      02-19-2008
http://www.velocityreviews.com/forums/(E-Mail Removed)-cnrc.gc.ca (Walter Roberson) writes:
> In article <(E-Mail Removed)>,
> Richard Heathfield <(E-Mail Removed)> wrote:
>>Harald van D?k said:

>
>>> On Mon, 18 Feb 2008 17:22:37 +0000, Richard Heathfield wrote:
>>>> Keith Thompson said:
>>>>> Richard Heathfield <(E-Mail Removed)> writes:
>>>>>> 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?

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Martin
Guest
Posts: n/a
 
      03-05-2008
On Feb 18, 6:42*pm, Ben Pfaff <(E-Mail Removed)> wrote:
> This was corrected in the corresponding paragraph of
> the C99 rationale: [...]


This is all rather unfortunate. K&R2, Plauger, http://flash-gordon.me.uk/ansi.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 have the C99 Standard, but my compiler doesn't support it.

--
Martin
 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      03-05-2008
In article <(E-Mail Removed)>,
Richard Heathfield <(E-Mail Removed)> wrote:

>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.)
--
"When a scientist is ahead of his times, it is often through
misunderstanding of current, rather than intuition of future truth.
In science there is never any error so gross that it won't one day,
from some perspective, appear prophetic." -- Jean Rostand
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      03-05-2008
In article <(E-Mail Removed)>,
Martin <(E-Mail Removed)> wrote:
>On Feb 18, 6:42=A0pm, Ben Pfaff <(E-Mail Removed)> wrote:
>> 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.)
--
"Any sufficiently advanced bug is indistinguishable from a feature."
-- Rich Kulawiec
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      03-05-2008
Walter Roberson said:

> In article <(E-Mail Removed)>,
> Richard Heathfield <(E-Mail Removed)> wrote:
>
>>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)


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.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      03-05-2008
In article <(E-Mail Removed)>,
Richard Heathfield <(E-Mail Removed)> wrote:
>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.


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.
--
"The beauties of conception are always superior to those of
expression." -- Walter J. Phillips
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Value of type Decimal cannot be converted to 1 dimensional array of Decimal Neal Software 0 03-20-2011 03:08 AM
TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why? Gilbert Fine Python 8 08-01-2007 01:58 AM
Conversion from Hexadecimal number into Decimal number dharmdeep@gmail.com C Programming 14 11-16-2006 07:51 PM
convert decimal number in a hexadecimal number ? muss C Programming 13 03-27-2006 08:14 AM
Convert decimal number in binary number makok VHDL 1 02-23-2004 06:04 PM



Advertisments