Why some things left undefined behavior in C++? Wouldn't it be better if some of them pre-defined in the standard?

Destructor

I am C++ programmer. While during surfing i became familiar with the terms like undefined behavior, unspecified behavior, implementation defined behavior etc. I am wondering why some things left undefined? I know that C++ is close to hardware but is it really hard to define a behavior for some of them? If so why they didn't do it? This question is about the philosophy behind leaving out so many behaviors open for compiler implementation. I think & believe that there are 2 following advantages of this:

1) It allows better performance. It simplifies the job of compiler, making it possible to generate very efficient code in certain situations.

2) It allows flexibility to compiler vendors to implement it in their own way.

If you know of any other factors other than performance please tell me. Your help will be highly appreciated.

Thanks

MSalters

Besides the reasons you already mentioned, one important thing is to understand that CPU's differ. They still do, but it used to be worse. Trying to specify exactly how C++ behaves in corner cases is just not helpful. E.g. 0/0 will be handled differently by different CPU's, and it doesn't really matter for real programs.

Another issue is that some UB is hard to detect . For instance, violations of the One Definition Rule across Translation Units would require support in the linker phase, and there's been quite some tolerance for vendors who rely on primitive linkers.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why some programs execute with undefined behavior and others don't?

From Dev

Why are some things defined twice in Scala's libraries?

From Dev

Why are some things defined twice in Scala's libraries?

From Dev

Address of + zero index, then dereference, undefined behavior in C in some circumstances or always?

From Dev

Why requireJs wouldn't load defined dependency modules?

From Dev

Why I can't see some controls when I'm using Syncfusion to docking them in C#.NET?

From Dev

I defined some things for my RPG, and it's not working

From Dev

Why i can't do some things without sudo using Python and pip?

From Dev

Why are some standard ocaml libraries opam packages and some are not?

From Dev

Regexp: forbid some characters in a pre-defined category

From Dev

C Standard Undefined Behavior With Respect To Nonportable Projects

From Dev

javascript inheritence why is property left out in some?

From Dev

Why are some methods defined with an uppercase first letter?

From Dev

some weird things at boot

From Dev

some weird things at boot

From Dev

Some chars can't be printed in standard output

From Dev

Why does the C++ standard's index have this entry for "undefined behavior"?

From Java

Why are these constructs using pre and post-increment undefined behavior?

From Dev

Why Can't I change the Standard Input for Vim to some file on disk using redirection?

From Dev

Why are some elements undefined in my slider script?

From Dev

Some puzzles about the subobject in the C++ Standard

From Dev

Why some C API doesn't follow Encapsulation

From Dev

Why a return statement of my user defined function doesn't work at some case?

From Dev

NoSQL database in python: What are some of the things that "shelve" can't do?

From Dev

Why do some C++ standard library `operator<<` functions reset their streams width to 0?

From Dev

Why do some of the functions in the OpenCV C++ interface have struct declarations in them?

From Dev

Why do some functions/variables have the character "_" in front of them , in C++ ?

From Dev

C# Winforms - Why are some controls updated in async event handler, but not all of them?

From Dev

Undefined method in some cases for instance method defined in a subclass

Related Related

  1. 1

    Why some programs execute with undefined behavior and others don't?

  2. 2

    Why are some things defined twice in Scala's libraries?

  3. 3

    Why are some things defined twice in Scala's libraries?

  4. 4

    Address of + zero index, then dereference, undefined behavior in C in some circumstances or always?

  5. 5

    Why requireJs wouldn't load defined dependency modules?

  6. 6

    Why I can't see some controls when I'm using Syncfusion to docking them in C#.NET?

  7. 7

    I defined some things for my RPG, and it's not working

  8. 8

    Why i can't do some things without sudo using Python and pip?

  9. 9

    Why are some standard ocaml libraries opam packages and some are not?

  10. 10

    Regexp: forbid some characters in a pre-defined category

  11. 11

    C Standard Undefined Behavior With Respect To Nonportable Projects

  12. 12

    javascript inheritence why is property left out in some?

  13. 13

    Why are some methods defined with an uppercase first letter?

  14. 14

    some weird things at boot

  15. 15

    some weird things at boot

  16. 16

    Some chars can't be printed in standard output

  17. 17

    Why does the C++ standard's index have this entry for "undefined behavior"?

  18. 18

    Why are these constructs using pre and post-increment undefined behavior?

  19. 19

    Why Can't I change the Standard Input for Vim to some file on disk using redirection?

  20. 20

    Why are some elements undefined in my slider script?

  21. 21

    Some puzzles about the subobject in the C++ Standard

  22. 22

    Why some C API doesn't follow Encapsulation

  23. 23

    Why a return statement of my user defined function doesn't work at some case?

  24. 24

    NoSQL database in python: What are some of the things that "shelve" can't do?

  25. 25

    Why do some C++ standard library `operator<<` functions reset their streams width to 0?

  26. 26

    Why do some of the functions in the OpenCV C++ interface have struct declarations in them?

  27. 27

    Why do some functions/variables have the character "_" in front of them , in C++ ?

  28. 28

    C# Winforms - Why are some controls updated in async event handler, but not all of them?

  29. 29

    Undefined method in some cases for instance method defined in a subclass

HotTag

Archive