| delorie.com/archives/browse.cgi | search |
| From: | "Richard Damon" <rdamon AT beltronicsinc DOT com> |
| To: | <djgpp AT delorie DOT com> |
| Subject: | RE: Static variables |
| Date: | Fri, 17 May 2002 14:12:56 -0400 |
| Message-ID: | <KBEEJNHPFAMCGLNKDFEFEEFIDKAA.rdamon@beltronicsinc.com> |
| MIME-Version: | 1.0 |
| X-Priority: | 3 (Normal) |
| X-MSMail-Priority: | Normal |
| X-Mailer: | Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) |
| X-MIMEOLE: | Produced By Microsoft MimeOLE V6.00.2600.0000 |
| In-Reply-To: | <ac39ir$m9gr2$1@ID-106847.news.dfncis.de> |
| Importance: | Normal |
| Reply-To: | djgpp AT delorie DOT com |
| Errors-To: | nobody AT delorie DOT com |
| X-Mailing-List: | djgpp AT delorie DOT com |
| X-Unsubscribes-To: | listserv AT delorie DOT com |
> -----Original Message-----
> From: Matthew Bayliss [mailto:noone AT knowhere DOT com]
> Sent: Friday, May 17, 2002 12:03 PM
> To: djgpp AT delorie DOT com
> Subject: Static variables
>
>
> I have a variable declared outside of main() with a static keyword.
>
> If you break on line 117 and "print words_ptr" the pointer has an
> assignment. When the function returns to main() (line 31) the
> variable has
> no value.
>
> Why is this? I thought a static variable would also keep it's
> value between
> funtions.
>
> Help.
...snip...
> static struct wordstruct *words_ptr;
...snip...
> int inputdata( struct wordstruct *words_ptr )
> {
...snip...
> }
>
Inside the function inputdata the parameter words_ptr will hide the global
words_ptr. Since it seams you want the global variable, make inputdata have
no parameters and just use the global.
Richard Damon
--
rbrdamon AT rcn DOT com (Home)
rdamon AT beltronicsinc DOT com (Work)
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |