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


Groups > comp.lang.c > #22897

Re: C scope and struct definitions

From pacman@kosh.dhis.org (Alan Curry)
Newsgroups comp.lang.c
Subject Re: C scope and struct definitions
Date 2012-06-27 20:59 +0000
Organization Aioe.org NNTP Server
Message-ID <jsfs87$lgn$1@speranza.aioe.org> (permalink)
References <mYGdnXsGt41dNnnSnZ2dnUVZ_u-dnZ2d@bestweb.net> <jsdbb6$t43$1@dont-email.me> <jsdcft$tga$1@speranza.aioe.org> <IKCdnQnYo6fW0HbSnZ2dnUVZ_qidnZ2d@bestweb.net>

Show all headers | View raw


In article <IKCdnQnYo6fW0HbSnZ2dnUVZ_qidnZ2d@bestweb.net>,
Kenneth Brody  <kenbrody@spamcop.net> wrote:
>On 6/26/2012 6:18 PM, Alan Curry wrote:
>> In article <jsdbb6$t43$1@dont-email.me>,
>> Eric Sosman  <esosman@ieee-dot-org.invalid> wrote:
>>> On 6/26/2012 4:08 PM, Alan Curry wrote:
>>>>
>>>> Scope is the boundary of a variable's existence at compile time.
>>>
>>>      Ah.  This is obviously some strange usage of the word "scope"
>>> that I hadn't previously been aware of.  More to the point, it's a
>>
>> It's an explanation of the concept, in my own words, deliberately chosen to
>> not look like standardese. I did that because I believe if you can't explain
>> something in your own words, you don't really understand it.
>
>But, you used "standardese" words to do so, thereby making it sound as if 
>you were misunderstanding the concepts.  If you're going to use words that 
>have a specific meaning in the context you're using them, but you choose to 
>use them for something else, you are at great risk for being misunderstood.

Well, "scope" is a word with standardized meaning, yes. And I think the
definition I provided above is 100% consistent with that standardized
meaning. It's just shorter because it's written in plain language (plain for
progammers anyway).

>
>> When you're writing the code
>> (as opposed to compiling and running it), the variable is the name. If you
>> saw something like
>>
>>    void foo(int i)
>>    {
>>      /*something*/
>>    }
>>
>>    int bar(void)
>>    {
>>      return i;
>>    }
>>
>> Wouldn't you think it's reasonable to say that the reason bar() won't compile
>> is that the variable i doesn't exist there?
>
>If you word it that way, yes.  If you were to use the more technical "not in 
>scope", then yes as well.  However, if you were to use something about the 
>"lifetime" of "i", then I would have to disagree.

That wouldn't be a normal usage coming from me either. I don't think I've
heard it before.

>
>> If you don't accept that wording,
>> then you're too much of a language lawyer to ever make sense of the way real
>> programmers talk.
>
>The problem was that you were using "scope" in a way different than its 
>defined meaning in the context of the C language.

I don't think I was. Show me where you think my definition of scope as "the
boundary of a variable's existence at compile time" diverges from a correct
definition.

>>>
>>>      Well, no.  Whenever an auto variable's identifier is in scope,
>>> that identifier exists, yes.  But the opposite does not hold: Even
>>> while the variable exists, its identifier can be out of scope.  (I
>>> can think of three ways for this to happen; there may be others.)
>>
>> That's a fun puzzle. Shadowing of course, which is a "don't do that".
>> Preprocessor effects ruled out, I assume. Maybe a variant of shadowing in
>> which typedef is used in an inner block.
>
>Not to mention a simple function call.
>
>     void foo(void)
>         {
>         int i;
>         bar();
>         }
>     void bar(void)
>         {
>         /* "i" still exists, but is out of scope. */
>         }

I wouldn't accept that as a solution to the puzzle as stated. The variable i
doesn't exist inside bar. At runtime, they may exist simultaneously, and you
can even add a way for bar to modify i by passing a pointer to it. But that's
only runtime coexistence. The variable "i" isn't fully present inside of bar.
So... half credit.

And everything I just said can be put down in dry sentences that perfectly
describe everything using the official terminology of "lifetime" and "scope".
I know how to write those sentences, I promise. But I still say there's room
for discussion among programmers using colloquial language, and that it can
be a more powerful form of communication than standard-quoting. Fall back on
standard-quoting when there's a dispute that can't be resolved any other way.

-- 
Alan Curry

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

C scope and struct definitions Kenneth Brody <kenbrody@spamcop.net> - 2012-06-22 13:30 -0400
  Re: C scope and struct definitions Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-22 14:02 -0400
    Re: C scope and struct definitions pacman@kosh.dhis.org (Alan Curry) - 2012-06-22 22:40 +0000
      Re: C scope and struct definitions Ben Pfaff <blp@cs.stanford.edu> - 2012-06-22 15:47 -0700
      Re: C scope and struct definitions Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-22 20:32 -0400
        Re: C scope and struct definitions pacman@kosh.dhis.org (Alan Curry) - 2012-06-23 22:06 +0000
          Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-23 16:18 -0700
            Re: C scope and struct definitions James Kuyper <jameskuyper@verizon.net> - 2012-06-25 10:19 -0400
              Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-25 11:51 -0700
          Re: C scope and struct definitions Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-23 19:54 -0400
            Re: C scope and struct definitions pacman@kosh.dhis.org (Alan Curry) - 2012-06-24 00:56 +0000
              Re: C scope and struct definitions Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-23 21:48 -0400
                Re: C scope and struct definitions pacman@kosh.dhis.org (Alan Curry) - 2012-06-24 06:03 +0000
                Re: C scope and struct definitions nick_keighley_nospam@hotmail.com - 2012-06-25 00:05 -0700
              Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-23 19:25 -0700
                Re: C scope and struct definitions pacman@kosh.dhis.org (Alan Curry) - 2012-06-24 05:40 +0000
                Re: C scope and struct definitions Jens Gustedt <jens.gustedt@loria.fr> - 2012-06-24 10:47 +0200
                Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-24 11:00 -0700
                Re: C scope and struct definitions pacman@kosh.dhis.org (Alan Curry) - 2012-06-25 03:53 +0000
                Re: C scope and struct definitions Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-25 01:14 -0400
                Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-24 22:38 -0700
                Re: C scope and struct definitions Kenneth Brody <kenbrody@spamcop.net> - 2012-06-25 11:03 -0400
                Re: C scope and struct definitions pacman@kosh.dhis.org (Alan Curry) - 2012-06-26 20:08 +0000
                Re: C scope and struct definitions Jens Gustedt <jens.gustedt@loria.fr> - 2012-06-26 23:21 +0200
                Re: C scope and struct definitions pacman@kosh.dhis.org (Alan Curry) - 2012-06-26 21:47 +0000
                Re: C scope and struct definitions Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-26 18:05 -0400
                Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-26 16:45 -0700
                Re: C scope and struct definitions Jens Gustedt <jens.gustedt@loria.fr> - 2012-06-27 08:26 +0200
                Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-27 00:01 -0700
                Re: C scope and struct definitions James Kuyper <jameskuyper@verizon.net> - 2012-06-27 06:57 -0400
                Re: C scope and struct definitions James Kuyper <jameskuyper@verizon.net> - 2012-06-27 15:00 -0400
                Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-27 14:48 -0700
                Re: C scope and struct definitions Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-27 16:14 -0700
                Re: C scope and struct definitions Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-29 09:36 -0700
                Re: C scope and struct definitions Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-27 16:27 -0700
                Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-27 12:03 -0700
                Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-27 12:11 -0700
                Re: C scope and struct definitions Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-27 15:53 -0700
                Re: C scope and struct definitions Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-26 17:59 -0400
                Re: C scope and struct definitions pacman@kosh.dhis.org (Alan Curry) - 2012-06-26 22:18 +0000
                Re: C scope and struct definitions Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-26 18:33 -0400
                Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-26 17:22 -0700
                Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-27 00:03 -0700
                Re: C scope and struct definitions Kenneth Brody <kenbrody@spamcop.net> - 2012-06-27 14:13 -0400
                Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-27 12:15 -0700
                Re: C scope and struct definitions Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-29 09:43 -0700
                Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-29 11:59 -0700
                Re: C scope and struct definitions Tim Rentsch <txr@alumni.caltech.edu> - 2012-07-01 18:32 -0700
                Re: C scope and struct definitions pacman@kosh.dhis.org (Alan Curry) - 2012-06-27 20:59 +0000
                Re: C scope and struct definitions Kenneth Brody <kenbrody@spamcop.net> - 2012-06-28 16:42 -0400
            Re: C scope and struct definitions James Kuyper <jameskuyper@verizon.net> - 2012-06-23 20:57 -0400
              Re: C scope and struct definitions Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-23 22:11 -0400
                Re: C scope and struct definitions James Kuyper <jameskuyper@verizon.net> - 2012-06-23 22:51 -0400
                Re: C scope and struct definitions Nick Bowler <nbowler@draconx.ca> - 2012-06-25 17:31 +0000
                Re: C scope and struct definitions James Kuyper <jameskuyper@verizon.net> - 2012-06-25 14:46 -0400
                Re: C scope and struct definitions Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-25 14:43 -0700
                Re: C scope and struct definitions Jens Gustedt <jens.gustedt@loria.fr> - 2012-06-26 13:44 +0200
                Re: C scope and struct definitions Keith Thompson <kst-u@mib.org> - 2012-06-23 20:07 -0700
              Re: C scope and struct definitions Jens Gustedt <jens.gustedt@loria.fr> - 2012-06-24 10:56 +0200
                Re: C scope and struct definitions James Kuyper <jameskuyper@verizon.net> - 2012-06-24 08:29 -0400
              Re: C scope and struct definitions Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-24 10:26 -0700
          Re: C scope and struct definitions Kenneth Brody <kenbrody@spamcop.net> - 2012-06-25 10:50 -0400
      Re: C scope and struct definitions Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-24 09:23 -0700
        Re: C scope and struct definitions Kenneth Brody <kenbrody@spamcop.net> - 2012-06-25 11:17 -0400
          Re: C scope and struct definitions Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-25 14:22 -0700
  Re: C scope and struct definitions Kenneth Brody <kenbrody@spamcop.net> - 2012-06-25 11:11 -0400

csiph-web