Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #151118
| From | Spiros Bousbouras <spibou@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Ways to avoid global variables |
| Message-ID | <ch88ItrMgKg0uu64vp@bongo-ra.co> (permalink) |
| References | <r6c5ie$5b9$1@dont-email.me> <r6ddj4$dvu$1@dont-email.me> <r6er3n$6le$1@dont-email.me> |
| Organization | virginmedia.com |
| Date | 2020-04-06 09:25 +0000 |
On Mon, 6 Apr 2020 13:30:38 +0430 Mehdi Amini <atorrses@gmail.com> wrote: > On 4/6/20 12:33 AM, David Brown wrote: > > On 05/04/2020 10:40, Mehdi Amini wrote: > >> Hi, > >> > >> What are the ways to avoid global variables in C > > > > The first question you should be asking yourself is "what do I mean by > > global variables" ? > > From this link: > https://www.codingunit.com/c-tutorial-functions-and-global-local-variables > > "A global variable is a variable that is declared outside all functions. " > > I would say without /static/ keyword. Seems like a reasonable definition to me and the kind of thing I would understand intuitively as a global variable. > > The second question you should be asking yourself is /why/ you think it > > is a good idea to avoid global variables in C? Is this just because you > > heard someone say it as a rule, or is it because you see it causing real > > problems? > > I think this is not standard practice to use global variables. Terms like "standard practice" are too vague to form the basis for useful (technical) discussion. They are suggestive without making any concrete claims. > Just like it is not OK to use goto. We already have one big issue in this thread , let's not start another. > I have been coding XBoard (a chess GUI) , it has lot's of global variables. Great , we now have something concrete to talk about. Can you mention some specific problems the global variables in the XBoard code caused for you ? > Unfortunately I added some more to it. Then perhaps you can give a specific example and people here can tell you if they consider some alternative preferable. Saying "Unfortunately" unnecessarily prejudices the discussion. -- Time for everyone to be socially responsible or be made to be PCC Marc Jones https://www.bbc.co.uk/news/uk-england-51988877
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Ways to avoid global variables Mehdi Amini <atorrses@gmail.com> - 2020-04-05 13:10 +0430
Re: Ways to avoid global variables Mehdi Amini <atorrses@gmail.com> - 2020-04-05 13:23 +0430
Re: Ways to avoid global variables felix@palmen-it.de (Felix Palmen) - 2020-04-05 11:11 +0200
Re: Ways to avoid global variables Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-05 02:34 -0700
Re: Ways to avoid global variables James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-05 10:48 -0400
Re: Ways to avoid global variables James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-05 11:43 -0400
Re: Ways to avoid global variables James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-05 16:49 -0400
Re: Ways to avoid global variables Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-05 16:12 -0700
Re: Ways to avoid global variables James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-05 11:49 -0400
Re: Ways to avoid global variables Mehdi Amini <atorrses@gmail.com> - 2020-04-06 14:11 +0430
Re: Ways to avoid global variables Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-06 12:08 +0100
Re: Ways to avoid global variables David Brown <david.brown@hesbynett.no> - 2020-04-05 22:03 +0200
Re: Ways to avoid global variables James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-05 16:53 -0400
Re: Ways to avoid global variables Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-05 14:11 -0700
Ice cream (Was: Ways to avoid global variables) gazelle@shell.xmission.com (Kenny McCormack) - 2020-04-06 06:45 +0000
Re: Ways to avoid global variables David Brown <david.brown@hesbynett.no> - 2020-04-06 09:19 +0200
Re: Ways to avoid global variables Mehdi Amini <atorrses@gmail.com> - 2020-04-06 13:30 +0430
Re: Ways to avoid global variables Spiros Bousbouras <spibou@gmail.com> - 2020-04-06 09:25 +0000
Re: Ways to avoid global variables Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-06 03:03 -0700
Re: Ways to avoid global variables Spiros Bousbouras <spibou@gmail.com> - 2020-04-06 10:16 +0000
Re: Ways to avoid global variables Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-06 03:21 -0700
Re: Ways to avoid global variables Spiros Bousbouras <spibou@gmail.com> - 2020-04-06 10:50 +0000
Re: Ways to avoid global variables David Brown <david.brown@hesbynett.no> - 2020-04-06 13:46 +0200
Re: Ways to avoid global variables scott@slp53.sl.home (Scott Lurndal) - 2020-04-06 18:05 +0000
Re: Ways to avoid global variables Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-06 20:37 +0100
csiph-web