[asterisk-users] Uninitialized variable in main/pbx.c?

Richard Kenner kenner at gnat.com
Wed Jan 23 21:06:58 CST 2013


> > +               dst_exten[0] = '\0';
> 
> Is this 'construct' prefered over
> 
>  		dst_exten[0] = 0;
>  	or
>  		*dst_exten = 0;
> 
> and why?

I'm somewhat of a C pedant here.  dst_exten is declared as an array,
not a pointer.  So if I want to clear the first byte of the array,
I'll use array syntax pretty consistently.  If it's a pointer, I tend
to prefer the pointer syntax, unless I'm also doing something with
other than the first byte.  So I wouldn't write:

      *x = 'a';
      x[1] = '\0';

but instead

      x[0] = 'a';
      x[1] = '\0';

And I certainly don't like using 0 when I mean "the null character",
at least not in an assignment.



More information about the asterisk-users mailing list