A
Ark Khasin
Consider a problem of exposing some
T foo;
for read-only access by other modules, in order to prevent inadvertent
(as opposed to malicious) writes to it. I cannot afford and/or do not
want to incur the overhead of access functions. A solution could be:
foo.h:
extern T foo;
#define foo ((const T)foo) //hide the original foo
foo.c:
#include "foo.h"
#undef foo
T foo;
There can be variations on this theme avoiding the often deprecated
#undef, like
foo.h:
extern T foo;
#ifndef OWNER_foo
#define foo ((const T)foo) //hide the original foo
#endif
foo.c:
#define OWNER_foo
#include "foo.h"
T foo;
What are NG's opinions on whether
- it looks right aesthetically
- it is a good idea to "overload" the identifier
- this can be a recommended practice (pattern) for a company's coding
standard
- (probably OT) this can confuse popular or bundled code browsers,
debuggers etc
T foo;
for read-only access by other modules, in order to prevent inadvertent
(as opposed to malicious) writes to it. I cannot afford and/or do not
want to incur the overhead of access functions. A solution could be:
foo.h:
extern T foo;
#define foo ((const T)foo) //hide the original foo
foo.c:
#include "foo.h"
#undef foo
T foo;
There can be variations on this theme avoiding the often deprecated
#undef, like
foo.h:
extern T foo;
#ifndef OWNER_foo
#define foo ((const T)foo) //hide the original foo
#endif
foo.c:
#define OWNER_foo
#include "foo.h"
T foo;
What are NG's opinions on whether
- it looks right aesthetically
- it is a good idea to "overload" the identifier
- this can be a recommended practice (pattern) for a company's coding
standard
- (probably OT) this can confuse popular or bundled code browsers,
debuggers etc