c - Why this line make my program segfault? -
i cut useless part of code make post clearer.
here problem, first , line in function init_dda()
make programme segfault, don't understand how possible, if have explanation, you.
void dda_algorithm(t_env *e) { t_dda *d; d = null; init_dda(e, d); } void init_dda(t_env *e, t_dda *d) { d->map_x = 3; }
here construction of structure t_dda
:
typedef struct s_dda { int map_x; } t_dda;
i have no compilation error warning flags enabled.
in init_dda()
call, you're passing second argument d
null.
then, inside init_dda()
, you're trying de-reference pointer. (dereferencing null pointer, invalid pointer) invokes undefined behaviour. segmentation fault 1 of side effects.
solution: need allocate memory d
before passing init_dda()
. can malloc()
, family of functions.
Comments
Post a Comment