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


Groups > comp.lang.c > #22447

Re: What a stupid gcc!

From "BartC" <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: What a stupid gcc!
Date 2012-06-21 00:13 +0100
Organization A noiseless patient Spider
Message-ID <jrtljp$fdc$1@dont-email.me> (permalink)
References (1 earlier) <0.d63dfcbf17c321e1d55d.20120619182205BST.87pq8vqksi.fsf@bsb.me.uk> <jrqmir$7q2$1@dont-email.me> <28Gdna63UOSAT3zSnZ2dnUVZ_g-dnZ2d@bestweb.net> <jrskm1$jpv$1@dont-email.me> <pOednUXiQILn0X_SnZ2dnUVZ_sudnZ2d@bestweb.net>

Show all headers | View raw


"Kenneth Brody" <kenbrody@spamcop.net> wrote in message 
news:pOednUXiQILn0X_SnZ2dnUVZ_sudnZ2d@bestweb.net...
> On 6/20/2012 9:54 AM, BartC wrote:
>> "Kenneth Brody" <kenbrody@spamcop.net> wrote in message
>> news:28Gdna63UOSAT3zSnZ2dnUVZ_g-dnZ2d@bestweb.net...
>>> On 6/19/2012 4:13 PM, BartC wrote:
> [...]
>>>> I'm sorry if no-one else can see the problems (duplicate declarations,
>>>> clutter, separating related variables, scattered declarations, trickier
>>>> editing because you have to keep moving the declarations around, 
>>>> worrying
>>>> about scope, shadowing, anonymity, etc).
>>>
>>> Ahh... So you want all declarations to be global scope, always?
>>
>> No. Function scope, file scope, and project-wide.
>
> So this:
>
>     void foo(void)
>         {
>         int i;
>         ...
>         }
>
> should (in your opinion) create a variable "i" of type integer with a 
> scope of the braces that encloses the declaration (ie: the function 
> "foo"), but:
>
>     void foo(void)
>         {
>         ...
>         if ( bar )
>             {
>             int i;
>             ...
>             }
>         ...
>         }
>
> should behave differently, and give "i" some scope other than the braces 
> that enclose the declaration?

Until a few days ago, I'd never even considered that variables could be 
declared local to a block. You second example was, to me, just a convenient 
way of declaring 'i' near the place where you started using it, but would 
have exactly the same scope as the ones at function level (ie. declared at 
the top of the function).

Now it seems the 'i' is limited to it's immediately enclosing braces, which 
doesn't appear so useful. Suppose it's an if-else statement, both branches 
having code that uses a variable 'i' of the same type; why bother declaring 
two distinct versions of it?

> [...]
>>> That eliminates the ability to create a "local" variable within a small
>>> block of code (I can't have a small loop use "int x,y", as that would
>>> simply be the same as the "double x,y" used elsewhere).  That eliminates
>>> basically everything useful about scope, because it eliminates scope
>>> entirely.
>>
>> No-one has said anything of the kind. Scope would still exist across 
>> modules,
>> across one module, and across one function. I'm saying it doesn't need to 
>> be
>> across individual blocks too, given that a typical function is small.
>
>     if ( foo.type == MyInteger )
>         {
>         int num;
>         num = foo.integer;
>         ... do stuff with int ...
>         }
>     else if ( foo.type == MyFloat )
>         {
>         float num;
>         num = foo.floating;
>         ... do stuff with float ...
>         }

I accept that it does allow you to do stuff like this, but it really doesn't 
seem a very good idea, using the same identifier for two different types, 
within a few lines of each other in the same function.

Imagine you're trying to read such a function, and your eyes jump from one 
part of the function to another. First num is a int; fine. Now you jump to 
the 'do stuff with float' part, and you have to do a double take. From this 
point on, you can't trust anything you see; what type is 'num' going to have 
next time you see it? Maybe these are two nested blocks in a loop, and you 
break from one to the other. You have to trace the code, character by 
character counting blocks, to match the use of 'num' with it's correct 
declaration.

Sorry, but these possibilities which everyone else thinks are great, to me 
just seem nightmarish.

> [...]
>>> How could one write a "small function" if it couldn't create variables
>>> that are available only within its scope?
>>
>> We're talking about adding extra block scopes to a 10- or 20-line 
>> function
>> that already has local variables valid throughout the function.
>>
>> How small a scope do you need: per line, per statement, or per 
>> expression?
>
> Why should the scope of a variable declared inside the outermost braces of 
> a function be different from a variable within some other set of braces? 
> What's difficult about the concept that the scope is the innermost set of 
> braces that enclose the declaration?

What is a set of braces? C uses braces to:

- Enclose the statements of a function body (which can't have just one 
non-block statement).

- Enclose an initialiser expression or list

- Group several ordinary statements into one. C statements such as while, 
for and if only allow one statement in a loop body or each branch of the 
'if', so {, } are a mechanism for allowing more than one.

The syntax could have used entirely different symbols for these 
requirements. Having a local scope for a function body, that's fine; every 
language except Basic has that. But what's so special about a compound 
statement that it ought to have it's own private set of variables?

On just about every other occasion where the complexity of a function grows 
beyond about 3 lines, I'm constantly told it needs to split into 
sub-functions. Now entire, self-contained sub-programs can be created in 
each branch of a minor 'if' in a minor 'for' loop in a dusty corner of a 
function, and that is perfectly OK?

In a different kind of forum from comp.lang.c, I would almost start to 
suspect a wind-up!

-- 
Bartc 

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


Thread

What a stupid gcc! zgene <nospam@nospam.com> - 2012-06-13 21:41 +0000
  Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-13 18:01 -0400
    Re: What a stupid gcc! Noob <root@127.0.0.1> - 2012-06-14 13:00 +0200
      Re: What a stupid gcc! Nomen Nescio <nobody@dizum.com> - 2012-06-14 14:33 +0200
        Re: What a stupid gcc! Rui Maciel <rui.maciel@gmail.com> - 2012-06-14 14:46 +0100
        Re: What a stupid gcc! Noob <root@127.0.0.1> - 2012-06-14 18:19 +0200
  Re: What a stupid gcc! Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-13 18:06 -0400
  Re: What a stupid gcc! jt@toerring.de (Jens Thoms Toerring) - 2012-06-13 22:19 +0000
    Re: What a stupid gcc! Rui Maciel <rui.maciel@gmail.com> - 2012-06-14 09:47 +0100
      Re: What a stupid gcc! Rui Maciel <rui.maciel@gmail.com> - 2012-06-14 14:37 +0100
  Re: What a stupid gcc! Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-06-13 17:05 -0600
  Re: What a stupid gcc! Nick Bowler <nbowler@draconx.ca> - 2012-06-14 00:09 +0000
  Re: What a stupid gcc! Varun Tewari <tewari.varun@gmail.com> - 2012-06-14 03:14 -0700
    Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-14 06:56 -0400
    Re: What a stupid gcc! Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-06-17 07:18 +0000
      Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-17 11:47 +0100
        Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-17 09:31 -0400
          Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-18 12:34 +0100
            Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-18 08:18 -0400
              Re: What a stupid gcc! gwowen <gwowen@gmail.com> - 2012-06-18 05:42 -0700
                Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-18 09:39 -0400
              Re: What a stupid gcc! Rich Webb <bbew.ar@mapson.nozirev.ten> - 2012-06-18 09:06 -0400
                Re: What a stupid gcc! ImpalerCore <jadill33@gmail.com> - 2012-06-18 07:18 -0700
            Re: What a stupid gcc! nick_keighley_nospam@hotmail.com - 2012-06-19 00:13 -0700
              Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-19 11:28 +0100
                Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-19 07:30 -0400
                Re: What a stupid gcc! nick_keighley_nospam@hotmail.com - 2012-06-20 00:16 -0700
        Re: What a stupid gcc! Rui Maciel <rui.maciel@gmail.com> - 2012-06-17 15:52 +0100
        Re: What a stupid gcc! Noob <root@localhost> - 2012-06-18 09:07 +0200
        Re: What a stupid gcc! Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-06-18 09:03 +0000
        Re: What a stupid gcc! Andrew Smallshaw <andrews@sdf.lonestar.org> - 2012-06-18 16:02 +0000
          Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-18 19:40 +0100
            Re: What a stupid gcc! Noob <root@localhost> - 2012-06-18 23:52 +0200
            Re: What a stupid gcc! Ike Naar <ike@iceland.freeshell.org> - 2012-06-18 23:09 +0000
              Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-19 01:30 +0100
                Re: What a stupid gcc! Ian Collins <ian-news@hotmail.com> - 2012-06-19 13:03 +1200
                Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-19 06:34 -0400
                Re: What a stupid gcc! Ike Naar <ike@sverige.freeshell.org> - 2012-06-19 08:43 +0000
                Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-19 11:00 +0100
                Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-19 07:05 -0400
                Re: What a stupid gcc! Ian Collins <ian-news@hotmail.com> - 2012-06-19 23:21 +1200
                Re: What a stupid gcc! Ian Collins <ian-news@hotmail.com> - 2012-06-19 23:22 +1200
                Re: What a stupid gcc! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-19 13:45 +0100
                Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-19 15:23 +0100
                Re: What a stupid gcc! Ike Naar <ike@iceland.freeshell.org> - 2012-06-19 16:14 +0000
                Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-19 18:01 +0100
                Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-19 13:59 -0400
                Re: What a stupid gcc! Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-06-19 15:29 -0600
                Re: What a stupid gcc! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-19 18:22 +0100
                Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-19 21:13 +0100
                Re: What a stupid gcc! Lew Pitcher <lpitcher@teksavvy.com> - 2012-06-19 16:27 -0400
                Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-19 16:38 -0400
                Re: What a stupid gcc! Kenneth Brody <kenbrody@spamcop.net> - 2012-06-20 09:47 -0400
                Re: What a stupid gcc! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-19 22:44 +0100
                Re: What a stupid gcc! nick_keighley_nospam@hotmail.com - 2012-06-21 01:39 -0700
                Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-21 10:55 +0100
                Re: What a stupid gcc! nick_keighley_nospam@hotmail.com - 2012-06-21 04:11 -0700
                Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-21 12:36 +0100
                Re: What a stupid gcc! David Brown <david@westcontrol.removethisbit.com> - 2012-06-21 15:33 +0200
                Re: What a stupid gcc! Andrew Smallshaw <andrews@sdf.lonestar.org> - 2012-06-21 14:15 +0000
                Re: What a stupid gcc! Kenneth Brody <kenbrody@spamcop.net> - 2012-06-20 09:37 -0400
                Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-20 14:54 +0100
                Re: What a stupid gcc! Kenneth Brody <kenbrody@spamcop.net> - 2012-06-20 18:19 -0400
                Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-21 00:13 +0100
                Re: What a stupid gcc! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-21 02:09 +0100
                Re: What a stupid gcc! nick_keighley_nospam@hotmail.com - 2012-06-21 02:05 -0700
                Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-21 11:49 +0100
                Re: What a stupid gcc! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-21 14:24 +0100
                Re: What a stupid gcc! nick_keighley_nospam@hotmail.com - 2012-06-22 00:38 -0700
                Re: What a stupid gcc! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-22 13:37 +0100
                Re: What a stupid gcc! nick_keighley_nospam@hotmail.com - 2012-06-21 01:57 -0700
                Re: What a stupid gcc! "BartC" <bc@freeuk.com> - 2012-06-21 11:46 +0100
                Re: What a stupid gcc! Kenneth Brody <kenbrody@spamcop.net> - 2012-06-21 14:37 -0400
                Re: What a stupid gcc! Andrew Smallshaw <andrews@sdf.lonestar.org> - 2012-06-21 19:38 +0000
                Re: What a stupid gcc! nick_keighley_nospam@hotmail.com - 2012-06-21 01:41 -0700
                Re: What a stupid gcc! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-21 12:28 +0100
              Re: What a stupid gcc! Kaz Kylheku <kaz@kylheku.com> - 2012-06-19 15:05 +0000
        Re: What a stupid gcc! Ian Collins <ian-news@hotmail.com> - 2012-06-19 09:37 +1200
          Re: What a stupid gcc! ImpalerCore <jadill33@gmail.com> - 2012-06-18 15:18 -0700
          Re: What a stupid gcc! Paul J Gans <gansno@panix.com> - 2012-06-18 23:21 +0000
            Re: What a stupid gcc! Ian Collins <ian-news@hotmail.com> - 2012-06-19 11:26 +1200
              Re: What a stupid gcc! Paul J Gans <gansno@panix.com> - 2012-06-19 01:46 +0000
                Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-19 07:19 -0400
                Re: What a stupid gcc! Stephen Sprunk <stephen@sprunk.org> - 2012-06-19 08:01 -0500
                Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-19 09:25 -0400
                Re: What a stupid gcc! Les Cargill <lcargill99@comcast.com> - 2012-06-19 12:57 -0500
                Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-19 14:59 -0400
            Re: What a stupid gcc! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-19 01:36 +0100
              Re: What a stupid gcc! Paul J Gans <gansno@panix.com> - 2012-06-19 01:48 +0000
          Re: What a stupid gcc! Les Cargill <lcargill99@comcast.com> - 2012-06-18 19:50 -0500
          Re: What a stupid gcc! nick_keighley_nospam@hotmail.com - 2012-06-19 00:19 -0700
            Re: What a stupid gcc! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-19 12:56 +0100
              Re: What a stupid gcc! nick_keighley_nospam@hotmail.com - 2012-06-20 00:26 -0700
                Re: What a stupid gcc! James Kuyper <jameskuyper@verizon.net> - 2012-06-20 06:31 -0400
      Re: What a stupid gcc! Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-06-18 00:18 -0600
        Re: What a stupid gcc! Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-06-18 09:15 +0000
  Re: What a stupid gcc! Kaz Kylheku <kaz@kylheku.com> - 2012-06-14 23:21 +0000

csiph-web