> -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu]On Behalf > Of Gerhard Fiedler > Sent: 27 April 2005 15:13 > To: Microcontroller discussion list - Public. > Subject: Re: [PIC] HiTech C and Local Variables > > > James wrote: > > > The contents of temporary local variables in some of my functions are > > getting overwritten without reason. By changing them to static it fixes > > the problem. > > > At no point does any of my code write to an address in RAM except via a > > pointer to a variable, so I can't see how these variables are getting > > overwritten. > > As you've been told already, since you are using pointers, nothing in the > PIC's address space is safe anymore :) > > Local automatic (non-static) variables are only valid as long as you are > executing the function that declares them or any function called by it. So > it's likely that the problem is in one of these places. > > If for example a function called by the one of which the local variables > get overwritten uses a pointer to its own local variables and the pointer > goes out of bounds, it could easily overwrite the local variables of the > calling function -- they may be right next to the function's own local > variables. Of course, declaring those overwritten variables removes /that/ > symptom of the problem, but doesn't really solve the problem :) > > > > I could raise this on HiTech's forum but that gets little traffic. I'm > > really looking for any experiences from people here that could backup or > > otherwise what I think I'm seeing! Many thanks. > > I've found that it's worth it to use the forum. It may have less traffic > overall than this list, but it's more targeted. > > Gerhard > -- Thanks Gerhard. I'll take a very close look, statically, at the code to see what might be happening. I'm guessing it will be obvious _once_ I see it! James -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist