Returns const struct member as non const in C: ok or bad?

Is this normal or can it be considered improper to return a data item pointer constnot constfrom const struct? What is the danger of not returning a pointer constas shown below?

widget_t * widget_child(const widget_t * parent)
{
if (!parent)
    return NULL;

return parent->child;
}
+4
source share
3 answers

const const -qualified struct , . , C .
, , () , (- /) .

const -qualified, C , , . .

+1

. ( , ). const. . . .

0

const C. , , : const . const readonly, C.

, , , .

: , .

0

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


All Articles