Re: Pass by ref vs. value

From: Wolfie (bgbdwolf_at_gte.net)
Date: 05/17/04


Date: Mon, 17 May 2004 04:10:32 GMT

RobertMaas@YahooGroups.Com wrote:

> Notice how you can cast a void
> pointer (return value from malloc) to any pointer type you want, for
> example you can allocate just one byte of memory but then cast the
> pointer to point to more than one byte, and call a function that
> clobbers all those bytes of memory, not just the one byte you
> allocated but several more bytes after it, and who knows what will
> happen, and the compiler and runtime system provide no protection
> against this. That's one reason only expert programmers who are
> careful not to make such mistakes should ever program in C.

It's one reason why even a beginning programmer should be wary
of casts, not a reason to avoid a whole language.

> (Why C, instead of LISP, is often taught as a first programming
> language for rank beginners is a great mystery to me. Maybe to
> scare away all but the best students, to reduce the number of
> unemployed programmers?)

C is a simple language that's incredibly easy to learn. It's like
chess, though -- few rules to learn but a 'lifetime' to master.
More than that, by learning C -- memory usage, the difference
between types, etc. -- one gets a fairly good feel for how the
platform actually works, something that's important to know
IMO.



Relevant Pages

  • Re: Is There Any Reason to Even Use VC++ Anymore?
    ... If, for another reason, the calling function needs to allocate memory, ... It does this by taking a pointer to a ball object ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Pointer to the out of scope local variables
    ... of a pointer, and jumped to the conclusion that you allocated the memory ... In this particular case the funtion buildPoint would allocate ... If the caller ...
    (microsoft.public.vc.language)
  • Re: Memory management and allocation
    ... > As I'm writing a piece of code that basically acts as a server and ... > memory management is a topic that is quite crucial. ... Or can I just allocate the variable ... Nor is it usually necessary to set the pointer to ...
    (comp.lang.c)
  • Re: Virtual Machine implementation problem, Please help me to spot the bug
    ... I kept on getting error messages. ... You don't allocate enough memory here. ... Again conversions between pointer and integer types. ...
    (comp.lang.c)
  • Re: This is getting really weird.
    ... I thought 4 bytes for reference count and 4 for string length. ... > There should be no memory allocation for that line. ... > manager may allocate more space than requested for its own efficiency. ... > that New returned with a pointer to the string constant. ...
    (alt.comp.lang.borland-delphi)