Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | pacman@kosh.dhis.org (Alan Curry) |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: C scope and struct definitions |
| Date | 2012-06-24 00:56 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <js5oki$9m3$1@speranza.aioe.org> (permalink) |
| References | <mYGdnXsGt41dNnnSnZ2dnUVZ_u-dnZ2d@bestweb.net> <js32rk$siv$1@dont-email.me> <js5ekh$lug$1@speranza.aioe.org> <js5l0m$64l$1@dont-email.me> |
In article <js5l0m$64l$1@dont-email.me>, Eric Sosman <esosman@ieee-dot-org.invalid> wrote: >On 6/23/2012 6:06 PM, Alan Curry wrote: >> In article <js32rk$siv$1@dont-email.me>, >> Eric Sosman <esosman@ieee-dot-org.invalid> wrote: >>> On 6/22/2012 6:40 PM, Alan Curry wrote: >>>> >>>> But is the compiler right for a real reason, or is it just a continuation of >>>> a historical accident? Why would you ever want this behavior? >>> >>> The Rationale sheds no light my tired old eyes can see. You >>> are welcome to read it for yourself. (Also, if you think the >>> normative text of the formal definition of the C language does not >>> qualify as "a real reason," well ...) >> >> The standard was supposed to codify existing practice. A real reason would >> have to come from before standardization. Was there a real reason for the >> existence of such a small, useless scope? > > Note that existing practice had no notion of prototypes at all, >so the issue of "prototype scope" simply didn't exist. (The ANSI >Standard invented other things new to the language, too: `void', >for example.) > > But once you've decided to declare a function with a prototype, >what scope should any identifiers in the prototype have? It seems >pretty clear you don't want them leaking outside, else > > void foo(char *p); > void bar(double *p); > >... wouldn't compile, because of the conflicting declarations of `p'. >I suggest that would have been untenable. Those names should simply be omitted, and it would be a good thing if they weren't allowed either. They serve no purpose and cause problems in header files when one header defines a macro that another header uses as an argument name in a prototype. We are allowed to use the intelligent comment markers /* */ in C, not just the dumb // to-end-of-line kind, so you can say void f(char * /*p*/, double * /*q*/); if the parameter names are meant to be documentation. Anyway, putting type names and variable names into a single category and calling them "identifiers" is a false generalization. It works at the technical level for the compiler implementor I guess, but besides that what's the reason for lumping them together and insisting that they behave the same? If you can't explain it without the word "identifier" then there is no reason, it's just a thought process that's being misled by a bit of escaped compiler-writer's jargon. >> >> I don't think we'd be losing anything if those declarations were simply >> illegal. Declare your structs before your functions. They aren't variables. > > I'm glad the Standard didn't take your view. While I'll admit >that function-specific types are not all that common, I'll maintain >that they are extremely useful. Most often, there's an ad-hoc >table of some kind to assist a function in the performance of its >work: Maybe an association of states with their capitols, or ranges >of `x' where a rational function/Chebyshev approximation/continued >fraction is the preferred computation method. Whatever it is, if >it's specific to the operation of one function I see *no* reason to >inflict it on others. The same could be said for a function that's only called by one other function. Should we have nested functions then? > >> A struct describes the procedure for interpreting bits in memory. As a >> procedure description, it's more like a function than a variable. It doesn't >> occupy memory itself, so it doesn't have a lifetime that can end when the >> function call ends. Putting it inside the function gives you nothing. > > All the same statements could be made about an identifier of any >kind whatsoever. Should `x' leak out of one function into others? Variable scopes make sense because the object named by the variable doesn't exist until the function is called. A type isn't an object. >> Variables, functions, and constant data are all defined with reference to >> types. Types are the most fundamental entities in a program. They deserve >> globally unique names. > > I'm with you, up to the antepenultimate word. Why should a >type declared in the bowels of some function in some library I don't >even have source to be "global?" How shall I select my identifiers >to ensure that no third party's library bollixes them? > > If you want "global," go back to BASICs. (By which I mean >Kemeny and Kurtz, not MS.) You don't have to take "global" that far. Third party libraries occupy separate globes. Uniqueness within a source file is a reasonable requirement. Uniqueness within a set of files that are compiled at the same time would be a good bonus check. -- Alan Curry
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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