Proposal to add modules to C with a simple extension.

robert thau thau at h-sc1.UUCP
Sun May 5 02:30:17 AEST 1985


> Overview:
> 	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. 

The syntax proposed is:
int really_global_var;	/* To set up context for the example ... */
{			/* Begin module */
	int module_var_1;	/* Variables invisible outside the module */
	char module_buffer[MAGICNUMBER];

	... functions using the variables ...
}

This leaves 

	int externfunc();
	{
		/* module here */
	}

looking too much like

	int externfunc()
	{
		/* Because of the missing ;, this becomes a function defn. */
	}

A new reserved word seems called for.

> 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.

I admit that this would make most module code a bit neater.  The problem
is that declarations in C are already a mess.  Function arguments declared
array are automatically coerced to pointer; variables declared in a compound
statement are of storage class auto by default, except if they're functions,
in which case the default is external, and so on.  The last thing the language
needs is yet another special case; my own humble opinion is that it would
be better to keep the default 'extern' of files, so as not to drive 
everybody nuts.

Aside from these gripes, I think the idea is a good one.

Robert Thau
rst at tardis.ARPA
h-sc1%thau at harvard.ARPA



More information about the Comp.lang.c mailing list