Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!mit.eternal-september.org!.POSTED!not-for-mail From: Richard Newsgroups: comp.lang.c Subject: Re: c prog -plz explain Date: Tue, 11 Mar 2014 08:39:50 +0100 Organization: http://www.ieee.org/ Lines: 36 Message-ID: <874n35b2ux.fsf@gmail.com> References: <71fb68ed-69a6-42da-b988-520f9c400ff4@googlegroups.com> <358734e3-251a-46cf-a653-d4ea7f5af8ce@googlegroups.com> <20140311001258.67@kylheku.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mit.eternal-september.org; posting-host="0884ca03534ef12a393eefc061e46422"; logging-data="13199"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19koK81YUINa3rLZ318zaS4LR3/eMpDkNQ=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:kdulAqoAYKiO2VTGoVNe8zvjgv8= sha1:eRMemaIg7FXMeahC1G3i7rIIrkM= Xref: csiph.com comp.lang.c:41600 Kaz Kylheku writes: > On 2014-03-11, SAHIL MAHLA wrote: >> Hi Pitcher , >> >> It's because we are typecasting i's address into a double* and then passing >> it to the incre() function. I know there is some issue with the typecasting >> itself.Passing like this is illegal ...is it???.....and my apologies for the >> silly abbrevations. > > Never mind the type casting being illega. > > Have you considerd that the type double and the type int do not even have the > same size? (They might, but often they do not. A common size for int is 32 > bits nowadays, and a double is often 64 bits.) > > What do you think happens when you pass a pointer to 32 bytes of storage > to a function which treats that as 64 bytes of storage? > Of course, that function stomps on memory outside of the object. > > The code could well crash. What if incme overwrites the return address on the > stack, so that when it tries to return back to main, it jumps into nowhere > land, resulting in an access violation or illegal instruction trap or something > of that sort? > > Listen, you better start replacing "I feel" with "I think", or find another > hobby. Don't give up your day job Kaz. Your insightful, friendly and, above all, helpful & professional input would be missed here. There was a time these groups were here to help and correct. Not to wallow in self indulgence as you put new programmers to the sword for making the same mistakes you and every other beginner made when you didnt know what a word or byte or pointer was properly.