Proposal to add modules to C with a simple extension.

Alexis Dimitriadis alexis at reed.UUCP
Sun May 5 17:00:58 AEST 1985


In article <224 at sdcc13.UUCP> ee163ahj at sdcc13.UUCP (PAUL VAN DE GRAAF) writes:

>	I'm sure most of you (like me) find the method of information hiding
>in C a bit excentric, but learn to live with it.  

>Proposal:
>	Allow blocks (modules) at the outermost (global) level of scope.
>The code inside of these blocks is treated as if it were in a separate file. 
>I think global variables within a module should be implied to be of "static"
>type within the module, and functions implied to be of "extern" type within
>the file that includes the module.  This explicitly shows which variables are
>shared within the module. [A minor point, I'll leave to language sematicians]
>Modules, of course, could be nested with the expected results.
>
>Analysis:
>	Implementing this change to the language is relatively painless.  All
>that is necessary is to treat modules as separate files.  Nested modules and
>my suggestion that a modules's globals be static may complicate things a bit,
>but not unduly.  As far as I can tell, only extra production need be added to
>the grammar (IE.  whatever -> '{' file '}').
>	Furthermore, it is downwardly (is this a word?) compatible to old C, and
>a logical extension of the blocks availiable within functions.


  Regardless of style, and (not very subtle) complications in
implementing this change so that it actually does something useful:

  What about letting functions in DIFFERENT files share hidden data?
That is, for me, the major stumbling block with the current semantics of
external statics.  The 'block' approach does not help any. (Unless you
can leave a block open at the end of the file!! :-)).  

  If you want strict NESTING of data hiding, you are still limited by 
being unable to declare a function inside a function.  And what about 
joe() sharing data with fred(), and sharing OTHER data with bob(),
without fred() and bob() sharing anything?

  If block structure is particularly applicable to a task, maybe you
should use Pascal. (hee, hee). (But not :-).  I think block structure
is one of the few genuine advantages of Pascal).

  For a general environment for data hiding, wait for C++.  It has all
sorts of things like structures with "private" parts, which can be
accessed only by "friend" functions.  (hmmm).  

Alexis
-- 
_______________________________________________
  As soon as I get a full time job, the opinions expressed above
will attach themselves to my employer, who will never be rid of
them again.

	  alexis @ reed

	 ...ihnp4! - tektronix!reed
	...decvax! /



More information about the Comp.lang.c mailing list