Re: realloc in function

From: Alexander Grigoriev (alegr_at_earthlink.net)
Date: 02/05/05


Date: Fri, 4 Feb 2005 21:47:12 -0800

This line pointed to one of your errors:

set1 = (int*)realloc(set1, *sizeSet1 * sizeof(int));

Note '&' removed before 'set1' argument.

My note about memory leak is also very important for proper use of realloc.

You should heed those who have mastered the language use, for they see the
'little' errors, which directly affect your code quality. You may have lots
of credentials in your field, but if you want to write software, listen to
professionals.

I'd recommend you to read "Code complete", by Steve McConnell.

"Ryan Rogers" <westhillian@hotmail.com> wrote in message
news:%23eJ9%230mCFHA.3976@tk2msftngp13.phx.gbl...
>
> First and foremost you know nothing about how I am in class. Some
> facts, since you seem pretty keen on speculating, are that I am on
> honours and I do go far beyond what the professors teach and expect from
> me. I sit on the dean's administrative counsel, and was senator for the
> school of Applied Computing and Engineering sciences oh and I've won a
> few awards, SSUI appreciation and the board of governors' appreciation
> award. I also have no problem in getting tech positions in my field,
> Magna, GlaxoSmithKline and RIM are among my latest contracts. Trust me I
> have the aptitude to take myself far regardless of what you state here
> in your petty assumptions to try to slander me.
>
> My initial question was not answered (to summarize): 'why do the
> values of my passed array incorrect when I return to the main function.'
> The response was
>
> " set1 = (int*)realloc(set1, *sizeSet1 * sizeof(int));
>
>
>
> Keep in mind that assigning realloc result to the same pointer may lead
> to memory leak, in case the allocation fails."
>
> Heck this isn't even an answer, but a statement about assigning realloc
> to the same point, legal but wrong; regardless still not the answer to
> my specific question.
>
> My question did fall into the correct category IMHO because I don't see
> a Microsoft.public.vc.memory listed. My desire to use C is also not
> misplaced, you're really bad at this assuming game, the course title is
> Systems Programming in C, not C++.
>
> "The post to which I replied had no such statement. Perhaps
> you are not yet aware that your posting have a very limited
> lifetime on many news servers."
>
> Why would you read Microsoft news from anywhere other then the MS news
> server or Google?
>
> As for being ignorant about the criteria of an MVP, I'll let curious
> readers decided.
>
> " MVPs earn their status by being nominated by peers and Microsoft
> Managers who see their consistent and accurate technical answers posted
> in the forums. The volunteer spirit of the MVPs and their positive
> online contribution helps create strong communities." -
> http://www.microsoft.com/india/mvp/default.aspx
>
> You're not going to be nominated with smart-ass responses
> Your sprit is not positive.
> Hmm guess I was right.
>
>
>



Relevant Pages

  • Re: CList Concept
    ... pointer instead of a list of object. ... called automatically by the list class destructor. ... CObject myObject = new CObject; ... if I do it this way, will I get memory leak? ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: question on malloc(0)
    ... the pointer returned by malloc, it's a memory leak regardless ... After the malloccall, ptr presumably ... points to some small allocated chunk of memory. ...
    (comp.lang.c)
  • Our very FIRST Competition
    ... Well we all seem to have news, good to see the posts coming in thick ... have a horse that is extremely forward going in walk, ... So plan is to make up the points when having to do the canter over the ... Pointer fashion) or he will just simply blow his brains, ...
    (uk.rec.equestrian)
  • Re: Probleme mit zu großer Memodatei
    ... Oder anderst herum: Da es keinen Pointer ... zum nächsten Block gibt, kann der tote Platz nicht einfach recycled werden. ... Das einzige, was am Anfang eines Memoblocks gespeichert wird, sind zwei ... Unsere MVPs bringen den Fuchs zum Laufen... ...
    (microsoft.public.de.fox)
  • Re: Parsing options in the same way they are passed to main
    ... > Jeff Rodriguez wrote: ... > This is also a guaranteed memory leak if realloc fails. ... > assign it to the destination pointer if it is non-null. ...
    (comp.lang.c)