Is it undefined behaviour to memcpy from an uninitialized variable?

前端 未结 3 1258
轻奢々
轻奢々 2020-12-20 11:24

Is using an uninitialized variable as the src for memcpy undefined behaviour in C?

void foo(int *to)
{
  int from;
  memcpy(to, &am         


        
3条回答
  •  遥遥无期
    2020-12-20 12:04

    ( Earlier -Didn't notice address of from is passed) . No , that won't cause undefined behaviour , just that from has indeterminate value. As far as you don't intend to use the value of uninitialized variable , program will have a well defined behaviour.

    (As allocating space and not initializing variables is not UB .)

提交回复
热议问题