Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
>
>
>
Undefined behavior

Undefined behavior

23 Mai 2015

Undefined behavior is a characteristic of certain programming languages (most prominent in C and C++) to produce a result in certain situations that depends on compiler implementation or specified optimization switches. In other words, the specification does not define the language's behavior in all possible situations but states: "in case of the A condition, the result of B operation is undefined". It is considered a mistake to allow such a situation in your program even if it is executed correctly with some particular compiler. Such a program won't be a crossplatform one and may cause failures on a different computer, operating system and even with different compiler's settings.

You should not mix up undefined behavior with unspecified behavior, the latter being the case when the specification does allow not every behavior possible but a restricted range of implementation variants.

Below are examples of situations causing undefined behavior:

  • Using a variable before initializing it. Undefined behavior occurs when trying to use the variable.
  • Memory allocation using the new [] operator and subsequent release using the delete operator. For example: T *p = new T[10]; delete p;. The correct code is: T *p = new T[10]; delete [] p;.
  • A variable is changed several times within one sequence point. As a canonical example, the i=i++ expression is often cited where assignment of the i variable and its increment are performed at the same time. To learn more about this kind of errors, read the section "sequence points".

References

Popular related articles

S'abonner

Comments (0)

close comment form
close form

Remplissez le formulaire ci‑dessous en 2 étapes simples :

Vos coordonnées :

Étape 1
Félicitations ! Voici votre code promo !

Type de licence souhaité :

Étape 2
Team license
Enterprise licence
** En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité
close form
Demandez des tarifs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
La licence PVS‑Studio gratuit pour les spécialistes Microsoft MVP
close form
Pour obtenir la licence de votre projet open source, s’il vous plait rempliez ce formulaire
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
I want to join the test
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
check circle
Votre message a été envoyé.

Nous vous répondrons à


Si l'e-mail n'apparaît pas dans votre boîte de réception, recherchez-le dans l'un des dossiers suivants:

  • Promotion
  • Notifications
  • Spam