On Sun, Apr 10, 2005 at 10:51:01PM -0400, wbounce wrote:
> If have serveral strcmp statements
>
> Originally I had them all like this.
>
> if (strcmp("GPGGA",gcBuffer) == 0)
> {
> gpFieldPtr=(PGM_P) GGA;
> }
>
> It would execute the pointer assignment on each of the 8 statements
>
> I changed them to
>
> lnResult = strcmp("GPGLL",gcBuffer);
> if (lnResult == 0)
> {
> gpFieldPtr=GLL;
> }
>
> So I could see the result code of strcmp. This time it skipped the 1st 3
> ok but then started doing the assignments. And when it got to the strcmp
> that should have matched, lnResult was not 0 and yet it did the
> assignment anyhow.
>
> Anyone have any idea why?
I'm not sure about the problem, but just a quick observation. With
AVR-GCC, string references like above consume both Flash as well as
precious RAM. It can add up quickly, too. To rewrite those to save
RAM space, try:
strcmp_P(PSTR("GPGLL"),gcBuffer);
This references the string data directly from Flash and saves making a
copy of it to RAM.
-Brian
--
Brian Dean
BDMICRO - ATmega128 Based MAVRIC Controllers
http://www.bdmicro.com/Message
Re: [AVR-Chat] Strcmp() problem stepping through AVR Studio
2005-04-12 by Brian Dean
Attachments
- No local attachments were found for this message.