int a = -2147483648;

K

Kenneth Brody

Jean-Marc Bourguet said:
Army1987 said:
On Sun, 08 Jul 2007 13:31:55 -0700, Keith Thompson wrote:
[snip]
How do we know how the implementor defines INT_MIN?
Like this:
#include <stdio.h>
#include <limits.h>
#define STR(x) STR_(x)
#define STR_(x) #x
int main(void)
{
puts(STR(INT_MIN));
return 0;
}
It is a strictly conforming program.

No. It's output is implementation dependant.

How strict is the definition of "strictly conforming program"? If
puts("Hello world.") outputs a different string for ASCII systems
versus EBCDIC systems, is this no longer "strictly conforming"?
(Yes, a display device which interprets ASCII/EBCDIC bit patterns
will display the same text, but the bits that are sent to stdout
are different.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
H

Harald van =?UTF-8?B?RMSzaw==?=

Army1987 said:
On Sun, 08 Jul 2007 13:31:55 -0700, Keith Thompson wrote:
[snip]
How do we know how the implementor defines INT_MIN?
Like this:
#include <stdio.h>
#include <limits.h>
#define STR(x) STR_(x)
#define STR_(x) #x
int main(void)
{
puts(STR(INT_MIN));
return 0;
}
It is a strictly conforming program.

No, it isn't, even if you take strictly conforming to ignore
implementation-defined output. INT_MIN -- and all other standard library
macros -- is allowed to be defined using a backslash for an implementation
extension in such a way that it cannot be stringised.
 
H

Harald van =?UTF-8?B?RMSzaw==?=

Army1987 said:
I said a *decimal* constant of 0x80000000, that is the literal
2147483648. I just wrote it in hex because I don't remember its
decimal digits by heart and I didn't think about copy&paste.

Ah, yes, you're right, I misread your message.
 
A

Army1987

Army1987 said:
On Sun, 08 Jul 2007 13:31:55 -0700, Keith Thompson wrote:
[snip]
How do we know how the implementor defines INT_MIN?
Like this:
#include <stdio.h>
#include <limits.h>
#define STR(x) STR_(x)
#define STR_(x) #x
int main(void)
{
puts(STR(INT_MIN));
return 0;
}
It is a strictly conforming program.

No. It's output is implementation dependant.
implementation-deï¬ned behavior
unspeciï¬ed behavior where each implementation documents how the choice is made

A strictly conforming program shall use only those features of the
language and library speciï¬ed in this International Standard. It shall
not produce output dependent on any unspeciï¬ed, undeï¬ned, or
implementation-deï¬ned behavior, and shall not exceed any minimum
implementation limit.

It says "implementation-defined *behavior*", not any i.d. feature.
IOW, it doesn't say that "the output must be identical on any
implementation". The behavior of puts() is not implementation-
defined, and neither is the behavior of # (except in the case of
universal character names). (Anyway, if this program isn't
strictly conforming, it is for the reasons stated by HvD.)
 
K

Keith Thompson

Army1987 said:
On Sun, 08 Jul 2007 13:31:55 -0700, Keith Thompson wrote:
[snip]
How do we know how the implementor defines INT_MIN?
Like this:
#include <stdio.h>
#include <limits.h>
#define STR(x) STR_(x)
#define STR_(x) #x
int main(void)
{
puts(STR(INT_MIN));
return 0;
}
It is a strictly conforming program.

No, it isn't, but in any case it doesn't answer my question.

I wasn't asking how we can determine how implementor defines INT_MIN;
I was questioning CBFalconer's apparent claim that we already know how
INT_MIN is defined, when I haven't seen any such information in the
discussion so far.

Here's what Chuck wrote:
| Not when the arithmetic is 2's complement. As this is used in the
| definition of INT_MIN by the implementor, he is allowed to know
| this.

It's possible I misunderstood his point. On re-reading it, I *think*
he meant that the *implementer* is allowed to assume 2's-complement
when writing the definition of INT_MIN, but I thought we were talking
about user code.
 
C

CBFalconer

Keith said:
.... snip ...

I wasn't asking how we can determine how implementor defines INT_MIN;
I was questioning CBFalconer's apparent claim that we already know how
INT_MIN is defined, when I haven't seen any such information in the
discussion so far.

Here's what Chuck wrote:
| Not when the arithmetic is 2's complement. As this is used in the
| definition of INT_MIN by the implementor, he is allowed to know
| this.

It's possible I misunderstood his point. On re-reading it, I *think*
he meant that the *implementer* is allowed to assume 2's-complement
when writing the definition of INT_MIN, but I thought we were talking
about user code.

You read me correctly. However, to me, any user code that just
uses the value of INT_MIN, via #include <limits.h>, IS conforming.
 
O

Old Wolf

implementation-de ned behavior
unspeci ed behavior where each implementation documents how the choice is made

Out of curiosity, why have you used a single character
for the two letters "fi", instead of using two characters?
A strictly conforming program shall use only those features of the
language and library speci ed in this International Standard. It shall
not produce output dependent on any unspeci ed, unde ned, or
implementation-de ned behavior, and shall not exceed any minimum
implementation limit.

The behavior of puts() is not implementation-defined,

I think it is either I-D or unspecified (as is the
behaviour of most of the functions in stdio.h)
because they could fail and return a negative value,
e.g. if the output stream is closed or has some
temporary problem.

(Assuming a hosted implementation -- the puts function
might not even exist on a freestanding one).
 
K

Keith Thompson

Old Wolf said:
Out of curiosity, why have you used a single character
for the two letters "fi", instead of using two characters?

Some document formats, including PDF, use a "ligature" to represent
certain pairs of characters. In typesetting, the consecutive letters
'f' and 'i' are typically printed as a single unit, with the 'i'
nestled under the 'f'. You can probably see examples in just about
any printed book.

With the right software, if you copy-and-paste text from such a
document, it *should* expand the ligature into separate characters 'f'
and 'i' (it works for me with Adobe Reader 8), but this doesn't always
happen.

I usually take the time to manually clean up any copy-and-pasted text
that I post here.
 
A

Army1987

Out of curiosity, why have you used a single character
for the two letters "fi", instead of using two characters?
Because I'd better get a better PDF reader.
I think it is either I-D or unspecified (as is the
behaviour of most of the functions in stdio.h)
because they could fail and return a negative value,
e.g. if the output stream is closed or has some
temporary problem.

So is this program not strictly conforming?
#include <stdio.h>
int main(void)
{
puts("hello, world");
return 0;
}
 
S

Spoon

Richard said:
Skybuck Flying wrote: [something]

warning CLC123: longstanding troll returns to comp.lang.c - suggest
archive check before composing reply.

He's been breaking our balls in comp.arch lately.

*sigh*
 
D

Default User

Spoon said:
Richard said:
Skybuck Flying wrote: [something]

warning CLC123: longstanding troll returns to comp.lang.c - suggest
archive check before composing reply.

He's been breaking our balls in comp.arch lately.

That's why they invented killfiles.




Brian
 
K

Keith Thompson

CBFalconer said:
You read me correctly. However, to me, any user code that just
uses the value of INT_MIN, via #include <limits.h>, IS conforming.

Of course a conforming program can use INT_MIN. But a program cannot
portably use the same expression that the implementation uses for
INT_MIN.

For example, this:
int i = INT_MIN;
is perfectly portable (though of course it can assign different values
to i on different implementations), but this:
int i = (-2147483647-1);
is not portable, even though some implementations may have
#define INT_MIN (-2147483647-1)
in <limits.h>.

The author of a system header (i.e., the implementer) has more freedom
to depend on implementation-specific behavior than ordinary
programmers do.

Or have I misunderstood your point again?
 
D

Daniel Rudy

At about the time of 7/8/2007 4:52 AM, Kenny McCormack stated the following:
That doesn't (wouldn't) matter to the anti-troll brigade.

Maybe so, but it is still a valid question.

So what happens to the value in a if you do the following?

int a = -2147483648;
a -= 1;

Where:

#define INT_MIN -2147483648

Do you get a == 2147483647 or 0x7FFFFFFF for a 32-bit int?


--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fsck more fsck yes spray umount sleep
 
R

Richard Bos

Daniel Rudy said:
So what happens to the value in a if you do the following?

int a = -2147483648;
a -= 1;

Where:

#define INT_MIN -2147483648

Do you get a == 2147483647 or 0x7FFFFFFF for a 32-bit int?

You get signed integer overflow, and therefore undefined behaviour.
--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fsck more fsck yes spray umount sleep

Fix yer sig.

Richard
 
D

Daniel Rudy

At about the time of 7/12/2007 11:20 PM, Richard Bos stated the following:
You get signed integer overflow, and therefore undefined behaviour.

Which can result in *ANYTHING* happening. I would imagine though that
it would roll the int. But I guess that's implementation dependent.
Fix yer sig.

Richard

Which part? The email or the computer joke?

--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fsck more fsck yes spray umount sleep
 
R

Richard Bos

Daniel Rudy said:
At about the time of 7/12/2007 11:20 PM, Richard Bos stated the following:

Which can result in *ANYTHING* happening. I would imagine though that
it would roll the int. But I guess that's implementation dependent.

Entirely true.
Which part? The email or the computer joke?

The being more than 4x80 part.

Richard
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,167
Latest member
SusanaSwan
Top