c++ - Type identity rule and its violation -


below code violating type identity rule (on ideone):

#include <iostream>  void foo() {     typedef int i;     extern a; //now denoting entity, member of global scope     std::cout << a; }  typedef char i; a; //definition of  int main() {     foo(); } 

the type identity rule(sec. 3.6/10 n3797):

after adjustments of types (during typedefs (7.1.3) replaced definitions), types specified declarations referring a given variable or function shall be identical, except declarations array object can specify array types differ presence or absence of major array bound (8.3.4). a violation of rule on type identity not require diagnostic.

i understand violation of rule not require diagnostic. why not?

the quoted rule means violation invokes undefined behavior.

the reasons not fully-specifying behavior are:

  • ease of implementation.
  • efficiency of program.
  • catering differing existing implementations.
  • allowing extensions , future evolution.

in case, object-file types not contain neccessary information diagnose error if distributed acrross multiple implementation units.
makes hard impossible diagnose.

anyway, c++ not contain method access different objects same name, putting information object files not idea, linker have know all rules c++ uses exceptions , corner-cases.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -