Re: C or C++ for FOSS/linux?



On 2006-12-29, Sebastian 'lunar' Wiesner wrote:
Jan Panteltje <pNaonStpealmtje@xxxxxxxxx> typed

[snip]

int *i = (int *) malloc (100*sizeof(int));

I don't know much of C programming, but that is known to me as the way
you allocate an array of 100 integers on the heap in C.

Wrong; it's:

int *i = malloc (100*sizeof(int));

You should not cast the value returned by malloc; that can mask
errors.

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
.



Relevant Pages

  • Re: WinCE Struct Help
    ... You can allocate *anything* with malloc() except a C++ object that needs to ... have its constructor called, so you can allocate your array with it, you can ... > Some of us just started programming while others are more advanced. ...
    (microsoft.public.windowsce.app.development)
  • Re: C or C++ for FOSS/linux?
    ... I don't know much of C programming, but that is known to me as the ... way you allocate an array of 100 integers on the heap in C. ... Freedom is always the freedom of dissenters. ...
    (comp.os.linux.development.apps)
  • Re: When will this ng come to accept that Fortran needs to go "back to the future" ?
    ... Fortran programming - I never felt a real need for it - and I wrote ... with higher array limits). ... After all - my company paid to send me to a 5-day C programming class ... as an allocable array of one dimension, with intrinsics (allocate, ...
    (comp.lang.fortran)
  • Re: Puppy Mastiff wants to Nip at Faces
    ... in my first college textbook on structured programming. ... they did was loop through an array to show how you could easily ... design, PIC code, and real time programming. ...
    (rec.pets.dogs.behavior)
  • Re: Cons cell archaic!?
    ... from s-expression or XML or other syntax you keep the bloated array ... For using vectors to emulate lists that ... Allocate 2, move 1 element: ... What do you think of that algorithm? ...
    (comp.lang.lisp)