S
Shao Miller
Good day, folks.
If we've an object which ought to contain _all_ of its relevant state
and we use a specific set of functions to deal with that object, might
it be nice to prevent those functions from accidentally including state
from outside the object?
For example, a 'nostatic' keyword (or whatever you like, as 'static
nostatic' is bound to confuse) used in:
static nostatic int foo_siblings(const struct foo * const foo_obj) {
/*
* This function cannot declare any static objects.
* This function cannot use any object identifiers
* which are not in the parameter list and are not
* in this block or a contained block.
* Type identifiers, struct/union/enum tags, function
* identifiers are fine.
*/
return foo_obj->brothers + foo_obj->sisters;
}
Could this kind of restriction help to ensure that programmers
developing the functions are bound to use only the state available in
the object?
Of course, being able to call other, non-'nostatic' functions would
easily enable one to circumvent this restriction, so maybe it wouldn't
be worth it.
If 'nostatic' functions could only call other 'nostatic' functions,
that'd limit/prevent use of the standard library, so that mightn't be
worth it.
Pick whatever keyword you like; perhaps it could be a meaning for the
'restrict' qualifier on functions? (Maybe not!)
Does anyone think it could be useful?... A means to specify that a
function doesn't "reach out" to objects beyond those that're provided to it?
If we've an object which ought to contain _all_ of its relevant state
and we use a specific set of functions to deal with that object, might
it be nice to prevent those functions from accidentally including state
from outside the object?
For example, a 'nostatic' keyword (or whatever you like, as 'static
nostatic' is bound to confuse) used in:
static nostatic int foo_siblings(const struct foo * const foo_obj) {
/*
* This function cannot declare any static objects.
* This function cannot use any object identifiers
* which are not in the parameter list and are not
* in this block or a contained block.
* Type identifiers, struct/union/enum tags, function
* identifiers are fine.
*/
return foo_obj->brothers + foo_obj->sisters;
}
Could this kind of restriction help to ensure that programmers
developing the functions are bound to use only the state available in
the object?
Of course, being able to call other, non-'nostatic' functions would
easily enable one to circumvent this restriction, so maybe it wouldn't
be worth it.
If 'nostatic' functions could only call other 'nostatic' functions,
that'd limit/prevent use of the standard library, so that mightn't be
worth it.
Pick whatever keyword you like; perhaps it could be a meaning for the
'restrict' qualifier on functions? (Maybe not!)
Does anyone think it could be useful?... A means to specify that a
function doesn't "reach out" to objects beyond those that're provided to it?