The C++ standard refers to the term "dynamic type" (and the C standard refers to "effective type" in the similar context), for example
<
The status quo is that malloc
does not create objects. The only constructs that do are new
expressions, definitions, casts and assignments to variant members. See P0137R0 for proper wording on this.
If you wanted to use the storage yielded by malloc
, assuming that it is properly aligned (which is the case unless you use extended alignments), employ a call to placement new:
auto p = malloc(sizeof(int));
int* i = new (p) int{0};
// i points to an object of type int, initialized to zero
Hence using malloc in C++ is quite useless, as bog-standard new
effectively combines the above steps into one.
See also @T.C.'s answer in the related question of the asker.