PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > Re: enum range
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: enum range

Réponse
 
LinkBack Outils de la discussion
Vieux 18/10/2007, 06h06   #1
Ark Khasin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: enum range

Keith Thompson wrote:
<snip>
> Of course signed integer overflow isn't required to
> result in wraparound. The compiler *could* set ``whats_this'' to 0,
> or to a value derived from the current phase of the moon.

<snip>

<OT>
I am afraid (really and truly) that the statement isn't incorrect.
I mean, we expect the compilation of the same translation unit with the
same command line of the compiler invocation to be repeatable. [It
wasn't on a version of my compiler and was acknowledged as a bug.]
Is there any wording somewhere to that end?
[I am afraid, no, or some linkers won't have a habit of planting a
timestamp in the executable.]
</OT>

--
Ark


  Réponse avec citation
Vieux 18/10/2007, 07h58   #2
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: enum range

Ark Khasin <akhasin@macroexpressions.com> writes:
> Keith Thompson wrote:
> <snip>
>> Of course signed integer overflow isn't required to
>> result in wraparound. The compiler *could* set ``whats_this'' to 0,
>> or to a value derived from the current phase of the moon.

> <snip>
>
> <OT>
> I am afraid (really and truly) that the statement isn't incorrect.
> I mean, we expect the compilation of the same translation unit with
> the same command line of the compiler invocation to be repeatable. [It
> wasn't on a version of my compiler and was acknowledged as a bug.]
> Is there any wording somewhere to that end?
> [I am afraid, no, or some linkers won't have a habit of planting a
> timestamp in the executable.]
> </OT>


In practice, most such behavior is likely to be repeatable. For
example, signed integer overflow *usually* wraps around, so INT_MAX+1
yields INT_MIN.

But the standard merely says that the behavior is undefined. If your
compiler has INT_MAX+1 yielding a value derived from the current phase
of the moon, you might want to complain to your vendor, but you can't
base your complaint on a violation of the standard, because there
isn't one. If you think of the standard as a contract between the
implementation and your program, it's your program that violated the
contract by attempting to compute INT_MAX+1 (or whatever).

More realistically, an optimizing compiler is allowed to *assume* that
anything invoking undefined behavior will never occur. This can lead
to surprising results.

Unless, of course, your vendor chooses to *document* the behavior of
signed integer overflow, effectively creating an addendum to the
contract.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h57.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07705 seconds with 10 queries