Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #17326 > unrolled thread

global/static variables & loops

Started byRob Janecek <robs@invalid.com>
First post2012-02-14 19:56 +0000
Last post2012-02-16 03:17 -0800
Articles 4 on this page of 64 — 18 participants

Back to article view | Back to comp.lang.c


Contents

  global/static variables & loops Rob Janecek <robs@invalid.com> - 2012-02-14 19:56 +0000
    Re: global/static variables & loops Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-14 12:42 -0800
    Re: global/static variables & loops Stephen Sprunk <stephen@sprunk.org> - 2012-02-14 15:01 -0600
    Re: global/static variables & loops Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-14 20:35 -0500
      Re: global/static variables & loops Philip Lantz <prl@canterey.us> - 2012-02-14 21:18 -0800
      Re: global/static variables & loops pete <pfiland@mindspring.com> - 2012-02-15 00:53 -0500
        Re: global/static variables & loops Jonathan Leffler <jleffler@earthlink.net> - 2012-02-18 21:15 -0800
          Re: global/static variables & loops Kaz Kylheku <kaz@kylheku.com> - 2012-02-19 06:05 +0000
            Re: global/static variables & loops Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-02-22 03:15 +0200
          Re: global/static variables & loops Shao Miller <sha0.miller@gmail.com> - 2012-02-19 04:14 -0500
            Re: global/static variables & loops Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-19 12:32 +0000
              Re: Array 'typedef's and exclusive use of '->' versus '.' Shao Miller <sha0.miller@gmail.com> - 2012-02-19 17:00 -0500
                Re: Array 'typedef's and exclusive use of '->' versus '.' Keith Thompson <kst-u@mib.org> - 2012-02-19 16:43 -0800
                  Re: Array 'typedef's and exclusive use of '->' versus '.' Shao Miller <sha0.miller@gmail.com> - 2012-02-19 20:32 -0500
                Re: Array 'typedef's and exclusive use of '->' versus '.' Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-02-22 03:27 +0200
                  Re: Array 'typedef's and exclusive use of '->' versus '.' Shao Miller <sha0.miller@gmail.com> - 2012-02-25 02:19 -0500
                    Re: Array 'typedef's and exclusive use of '->' versus '.' Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-02-25 10:14 +0200
      Re: global/static variables & loops "BartC" <bc@freeuk.com> - 2012-02-15 10:47 +0000
        Re: global/static variables & loops Kaz Kylheku <kaz@kylheku.com> - 2012-02-15 11:42 +0000
          Re: global/static variables & loops "BartC" <bc@freeuk.com> - 2012-02-15 12:54 +0000
          Re: global/static variables & loops Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-15 05:17 -0800
        Re: global/static variables & loops Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-02-22 03:28 +0200
      Re: global/static variables & loops August Karlstrom <fusionfile@gmail.com> - 2012-02-15 15:19 +0100
      Re: global/static variables & loops Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-02-22 03:12 +0200
    Re: global/static variables & loops Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-15 01:23 -0800
      Re: global/static variables & loops August Karlstrom <fusionfile@gmail.com> - 2012-02-15 14:03 +0100
        Re: global/static variables & loops Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-15 05:20 -0800
          Re: global/static variables & loops James Kuyper <jameskuyper@verizon.net> - 2012-02-15 08:41 -0500
            Re: global/static variables & loops Kaz Kylheku <kaz@kylheku.com> - 2012-02-16 00:20 +0000
              Re: global/static variables & loops Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-15 21:02 -0500
                Re: global/static variables & loops "BartC" <bc@freeuk.com> - 2012-02-16 10:03 +0000
                  Re: global/static variables & loops Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-16 07:58 -0500
                Re: global/static variables & loops Markus Wichmann <nullplan@gmx.net> - 2012-02-19 20:44 +0100
                  Re: global/static variables & loops Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-19 15:37 -0500
                  Re: global/static variables & loops Kaz Kylheku <kaz@kylheku.com> - 2012-02-22 05:01 +0000
                    Re: global/static variables & loops Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-22 08:12 -0500
      Re: global/static variables & loops Anders Wegge Keller <wegge@wegge.dk> - 2012-02-15 15:55 +0100
        Re: global/static variables & loops James Kuyper <jameskuyper@verizon.net> - 2012-02-15 11:05 -0500
        Re: global/static variables & loops Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-15 09:13 -0800
          Re: global/static variables & loops Anders Wegge Keller <wegge@wegge.dk> - 2012-02-15 18:25 +0100
            Re: global/static variables & loops James Kuyper <jameskuyper@verizon.net> - 2012-02-15 13:25 -0500
              Re: global/static variables & loops Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-15 10:51 -0800
                Re: global/static variables & loops James Kuyper <jameskuyper@verizon.net> - 2012-02-15 14:45 -0500
                Re: global/static variables & loops Anders Wegge Keller <wegge@wegge.dk> - 2012-02-15 20:47 +0100
                  Re: global/static variables & loops Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-16 04:45 -0800
                    Re: global/static variables & loops Anders Wegge Keller <wegge@wegge.dk> - 2012-02-16 14:25 +0100
                      Re: global/static variables & loops Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-16 08:10 -0800
                      Re: global/static variables & loops Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-17 00:59 -0800
              Re: global/static variables & loops Anders Wegge Keller <wegge@wegge.dk> - 2012-02-15 20:30 +0100
                Re: global/static variables & loops James Kuyper <jameskuyper@verizon.net> - 2012-02-15 15:00 -0500
                  Re: global/static variables & loops Anders Wegge Keller <wegge@wegge.dk> - 2012-02-15 21:30 +0100
                    Re: global/static variables & loops James Kuyper <jameskuyper@verizon.net> - 2012-02-15 16:00 -0500
                      Re: global/static variables & loops Anders Wegge Keller <wegge@wegge.dk> - 2012-02-15 23:10 +0100
                        Re: global/static variables & loops Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-15 15:50 -0800
                        Re: global/static variables & loops James Kuyper <jameskuyper@verizon.net> - 2012-02-15 19:50 -0500
                          Re: global/static variables & loops Anders Wegge Keller <wegge@wegge.dk> - 2012-02-16 14:36 +0100
              Re: global/static variables & loops Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-16 03:29 -0800
        Re: global/static variables & loops Anders Wegge Keller <wegge@wegge.dk> - 2012-02-15 23:37 +0100
        Re: global/static variables & loops Kaz Kylheku <kaz@kylheku.com> - 2012-02-16 00:23 +0000
          Re: global/static variables & loops Anders Wegge Keller <wegge@wegge.dk> - 2012-02-16 01:29 +0100
          Re: global/static variables & loops Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-15 21:20 -0500
        Re: global/static variables & loops Shao Miller <sha0.miller@gmail.com> - 2012-02-15 22:24 -0500
          Re: global/static variables & loops Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-16 01:08 -0800
        Re: global/static variables & loops Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-16 03:17 -0800

Page 4 of 4 — ← Prev page 1 2 3 [4]


#17415

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2012-02-15 21:20 -0500
Message-ID<jhhp57$geu$1@dont-email.me>
In reply to#17407
On 2/15/2012 7:28 PM, Stefan Ram wrote:
> Kaz Kylheku<kaz@kylheku.com>  writes:
>> You're bending the definition of global variable beyond what is reasonable.
>
>    Then show me the »definition of global variable«.

     The C language has no definition for the term (as I'm fairly
sure you know).

     Often, what people mean by "global variable" is "a variable with
static duration whose identifier has external linkage."  Sometimes a
phrase like "file global" or "local global" (hey, I didn't invent it!)
means "a variable with static duration whose identifier has internal
linkage."  I have never seen the word "global" attached to a variable
whose identifier has no linkage.

     And then there are people who'll use "global" to refer to things
that aren't "variables" in C-speak, but which encapsulate or provide
access to some piece of program-wide state.  Elsethread I used `stdout'
in this way and caught pedantflak for doing so, but since "global"
itself is not defined by C I'm not too sure what ground the pedants
stand upon.  At an uncommon stretch, `getenv("SHELL")' could be said
to be "a global," though I personally wouldn't use the term that way.

     So, what are the concerns raised about "globals" in this thread?
I see two:

     - First, access to a "global" variable may be slower than access
       to some other variables, or the use of a "global" may inhibit
       optimizations the compiler might otherwise be able to perform.
       My take: Probably not worth worrying about.  Certainly not worth
       worrying about "Yet," in the sense of Jackson's Laws.

     - Second, the universal availability of a "global" variable can
       produce unanticipated interactions between (supposedly) unrelated
       pieces of the program.  To my mind, this is by far the worse
       drawback.

     Globals are not Evil, just Perilous.  They are not to be rejected
altogether, but neither should they be used liberally.  If you can make
a good case for `X' being global, go ahead and make it so -- but first,
be sure you can make the case.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


#17416

FromShao Miller <sha0.miller@gmail.com>
Date2012-02-15 22:24 -0500
Message-ID<jhhsof$u45$1@dont-email.me>
In reply to#17373
On 2/15/2012 09:55, Anders Wegge Keller wrote:
> Nick Keighley<nick_keighley_nospam@hotmail.com>  writes:
>
>> Oh, and why does your progranm have global variables in the first
>> place?
>
>   Can you give an example of a non-trivial program, that has no global
> state in any way?
>

If, by "global state," you mean static-duration objects, I think I'm 
working on such a library right now.  It doesn't link with the Standard 
Library, but requires [its own library] users to pass a pointer to a 
structure with function pointer members for any functions that the 
library can't implement without depending on other libraries or 
operating system.  The library-using caller might have global state, but 
the library doesn't.

However even if all of this is squeezed through a single exported 
function, that exported function could be considered "a global," of 
sorts, though not a static-duration object.

Speaking of which, would 'const'-qualified global objects be considered 
"global state?"  And string literals, that ought to be treated as 
'const'?  I wouldn't think so, but perhaps opinions differ.

[toc] | [prev] | [next] | [standalone]


#17423

FromMalcolm McLean <malcolm.mclean5@btinternet.com>
Date2012-02-16 01:08 -0800
Message-ID<4214dc40-0ef0-41c3-9aec-3f56f02c8219@1g2000yqv.googlegroups.com>
In reply to#17416
On Feb 16, 3:24 am, Shao Miller <sha0.mil...@gmail.com> wrote:
>
> Speaking of which, would 'const'-qualified global objects be considered
> "global state?"  And string literals, that ought to be treated as
> 'const'?  I wouldn't think so, but perhaps opinions differ.
>
No. State is modified during the duration of the program. So compile
time constants are not state.

[toc] | [prev] | [next] | [standalone]


#17433

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2012-02-16 03:17 -0800
Message-ID<990174da-b34d-44a0-82f3-bd9667eaf509@t2g2000yqk.googlegroups.com>
In reply to#17373
On Feb 15, 2:55 pm, Anders Wegge Keller <we...@wegge.dk> wrote:
> Nick Keighley <nick_keighley_nos...@hotmail.com> writes:

> > Oh, and why does your progranm have global variables in the first
> > place?
>
>  Can you give an example of a non-trivial program, that has no global
> state in any way?

I was encouraging him consider if he needed a global variable.
Excluding stuff from the standard library plenty of small non-trivial
programs can be written without global state. I'll have to hunt around
some of my software. If there are no extern variables does that count?

[toc] | [prev] | [standalone]


Page 4 of 4 — ← Prev page 1 2 3 [4]

Back to top | Article view | comp.lang.c


csiph-web