Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

memory allocation of a pseudo-generic nested array

(*((_SINGARR) _receptive->__m2dimensio + g_curr++)) = (_SINGARR) malloc(sizeof(*((_SINGARR)(_generic)) * g));

the aforementioned produces the following compiler warning
"assignment makes integer from pointer without a cast "

I suppose it’s somehow procured by the sizeof operator evaluation of the typecasted dereferenced void* or am I just not dereferencing accordingly?

_generic is a void* method parameter

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

_receptivetypedef struct* method parameter used in the accessing of its 2D-array property (also pseudo-generic)

expanded directives

_SINGARR char*

>Solution :

When you expand all the stuff, it looks like

* (char*) p = (char*) malloc(...);

This means, there is a pointer on the right side (char*) and a character (*(char*), integer type) on the left side.

Now the warning message becomes clearer:

assignment makes integer (the part on the left side of the assignment) from pointer (the part on the right side of the assignment) without a cast


Unrelated, but expanding the sizeof(...) part will become sizeof(*((char*)(_generic)) * g), which in turn is sizeof(<some character value> * g), which in turn will become sizeof(<some integer value>), which is sizeof(int) and finally becomes 4 or 8 bytes depending on the architecture of your machine.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading