lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Coroutines once stated:
> On Sat, Apr 19, 2014 at 2:18 PM, Sean Conner <sean@conman.org> wrote:
> 
> >  Perhaps in time it'll be reguarded like the "register" keyword, accepted, but totally ignored.
> 
> The liberal in me wants register, inline, const, auto, and maybe even
> restrict to be removed from the list of C keywords.  gcc & clang-llvm
> are so smart nowadays (imo) these keywords are more misused than used
> appropriately :(  volatile can never be made useless by a
> self-aware/skynet compiler though, haha

  I can see register and auto being removed, but the rest, even if the
compiler ignores them, also registers (heh) intent.  Given two prototypes:

	int foo(const char *x);
	int bar(char *x);

I know I can safely pass in a string to foo() and not have it change on me;
I don't know that about bar() without checking the source code. One says
"I'll only read the data," the other says "there be dragons."

  I also use const in a design pattern.  I place all my global variables in
one file (usually globals.c):

	char *c_name;
	char *c_foo;
	int   c_blah;

  Also in that file (globals.c) is code that will modify those variables (I
tend to place the command line parsing routines here).  In a header file
(usually globals.h) I defined them as:

	extern const char *const c_name;
	extern const char *const c_foo;
	extern const int         c_blah;

  Any attempt to modify those variables outside of globals.c is flagged as
an error (I should note that globals.c does *NOT* include globals.h).  

  I do try to minimize the number of global variables I use, but sometimes
their use is unavoidable.  I have several examples of this design pattern
[1][2].

  -spc

[1]	And it is a design pattern, as it's a workaround for a flaw in the
	language.

[2]	https://github.com/spc476/mod_blog/tree/master/src
	https://github.com/spc476/x-grey/tree/master/server/src