[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Language War (Re: "C" Manual)



On Mon, Dec 31, 2001 at 09:15:26PM -0600, Richard Cobbe wrote:
> 
> > most of the segfaults are because of the resource allocation mistakes,
> > not because of mistaken types... at last that's my impression.
> 
> Resource allocation mistakes (at least, the kind that typically lead to
> seg faults) *are* type errors, from a certain point of view.
> 
> Consider the following:
> 
>     char *a, *b;
> 
>     a = strdup("This is a sample string");
>     b = a;
> 
>     free(a);
> 
>     /* Much code follows here, none of which modifies b. */
> 
>     printf("%s\n", b);

Uh, for one, this wont segfault.

Secondly, you can make this mistake with any language that allows
references (perl, python, and java all allow it). Just replace free()
with some other assignment that changes what a is, and ultimately you
change b, which referenced it, unintentionally.

-- 
 .----------=======-=-======-=========-----------=====------------=-=-----.
/                   Ben Collins    --    Debian GNU/Linux                  \
`  bcollins@debian.org  --  bcollins@openldap.org  --  bcollins@linux.com  '
 `---=========------=======-------------=-=-----=-===-======-------=--=---'



Reply to: