J
jacob navia
After reading some of the contrbutions to the "constant strings" thread,
I think that what is needed is a clarification of the underlying issues.
There are TWO "uses" of const:
1) Declaring that a function will not modify its arguments
2) Declaring that an object resides in ROM (read only memory)
The first one is tied to a *scope*. It says that within a certain scope,
no modifications are done to some object. I would propose that we name
this property "constant" and we would declare:
char *strchr(constant char *buffer, int searchedChar);
This means: "The strchr functions receives a buffeer that will NOT be
modified within the scope of the function". This implies that inner
scopes are required to maintain this feature. It means also that when we
exitthe scope where this "constant" declaration is done, the object
becomes writable again. Hence it is normal that strchr returns a *plain*
char pointer. "constant" objects can't be returned as constant.
The second meaning of const is the usual one and it is tied to an
*object* not a scope. It means that the object can't be modified at
*any* scope, it is an intrinsic property of the object.
In my opinion many problems with "const" would disappear if we
distinguish between these two usages of const.
Feedback welcome.
I think that what is needed is a clarification of the underlying issues.
There are TWO "uses" of const:
1) Declaring that a function will not modify its arguments
2) Declaring that an object resides in ROM (read only memory)
The first one is tied to a *scope*. It says that within a certain scope,
no modifications are done to some object. I would propose that we name
this property "constant" and we would declare:
char *strchr(constant char *buffer, int searchedChar);
This means: "The strchr functions receives a buffeer that will NOT be
modified within the scope of the function". This implies that inner
scopes are required to maintain this feature. It means also that when we
exitthe scope where this "constant" declaration is done, the object
becomes writable again. Hence it is normal that strchr returns a *plain*
char pointer. "constant" objects can't be returned as constant.
The second meaning of const is the usual one and it is tied to an
*object* not a scope. It means that the object can't be modified at
*any* scope, it is an intrinsic property of the object.
In my opinion many problems with "const" would disappear if we
distinguish between these two usages of const.
Feedback welcome.