c - How to interpret section 6.3.2.3 part 7 of the C11 standard? -


in context of question there discussion on whether allowed (i.e. or not introduce implementation defined or undefined behavior) cast int** void** , subsequently assign value dereferenced void*. brings me question on interpretation of c11 standard

6.2.5 (28) pointer void shall have same representation , alignment requirements pointer character type. ...
6.3.2.3 (1) pointer void may converted or pointer object type. pointer object type may converted pointer void , again; result shall compare equal original pointer.
6.3.2.3 (7) ... when pointer object converted pointer character type, result points lowest addressed byte of object. ...

my question whether this

int* intptr = null; void* dvoidptr = &intptr; /* 6.3.2.3 (1) */ *(void**)dvoidptr = malloc(sizeof *intptr); /* using 6.3.2.3 (1) */ 

conforms standard or not? seems strange me, cannot find conclusive line of argument why not. void* void** guaranteed 6.3.2.3 , 6.2.5 6.3.2.3 alignment.

code not valid.

see emphasis:

6.3.2.3 (1) pointer void may converted or pointer object type. pointer object type may converted pointer void and again; result shall compare equal the original pointer.

you converting int** void* (fine), , different type void** (not ok). c gives no quarantee can safely convert void* other original type (aside converting char *)

in addition, *(void**)dvoidptr results in void* when in reality there int*. if, example, sizeof(void*) == 2 , sizeof(int*) == 1? can convert void* pointer other type, cannot reinterpret directly other type.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -