Why is the assignment of a double ** to void ** warning?

The following code works exactly as expected, but the compiler gives me an incompatible pointer type warning. Casting will solve this, but I really don't understand why this should be a warning. The pointer is an integer, which is the address of a specific memory area, and in my example, v has the address d, which is an integer, and that all seems to be. Please help me understand this problem.

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    double *d;
    void **v;

    d = malloc(sizeof(double));
    *d = 1.1;
    printf("%.1f\n", *d);
    v = &d;
    *(double *)*v = 2.2;
    printf("%.1f\n", *d);
    return 0;
}
+4
source share
1 answer

I wanted to post this as a comment, but I still don't have a reputation ...: - /

, , - . , . , , .

, :

short s = 5;
int i = 6;
printf("s: 0x%X -> 0x%X\n", &s, (&s)+1);
printf("i: 0x%X -> 0x%X\n", &i, (&i)+1);

:

s: 0x270A724E -> 0x270A7250                                              
i: 0x270A7248 -> 0x270A724C

, s ( 4E 50, a short) i ( 48 4C, a int). (&s)+1 . , []. , char *str , str++.

+2

Source: https://habr.com/ru/post/1568175/


All Articles