c++ - Is there any documentation about pointers' compatible types? -


i have tried searching without luck. have read pointers , used them , know pointers non-class types compatible same pointer type, like

int* apointer = anotherintpointer; 

but not possible(not without explicit conversion)

int* apointer = afloatpointer; 

i see point in not allowing this, not totally. like, integers compatible floating-points, int x = afloatvariable;, why should pointers int not compatible pointers float?

my main question is: there place can read why pointers compatible same pointer type , place states true, because assumption experience. if can read in standard, please give me hint read, because not find when skimmed it. if provide me link or something, more awesome.

edit: based on comments, can see use of word compatible maybe little off. mean compatible 1 type allowed assigned :)

integers compatible floating-points, why should pointers int not compatible pointers float?

integers , floats have different representation in memory. reason compatible compiler provides implicit conversion "magic". when write

float f = someint; 

the compiler inserts cpu instructions convert someint value float representation.

the compiler can because knows @ compile time someint int , f float. if have pointer float, , write

float f = *pointertofloat; 

but pointer pointing int, compiler think pointer pointing float, because there no other type associated pointertofloat. compiler must trust whatever pointer pointing float representation, end re-interpreting int float, unexpected (and undefined) results.

if can read in standard, please give me hint read

there 2 parts of the standard relevant pointer conversion - part 3.7.4.3.2, explains safely-derived pointers can be, among other things, result of well-defined pointer conversion, , part 4.10, lists 3 kinds of pointer conversions relevant primitive data types.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -