Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Exposing global...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 16 Topic 24867 of 27317
Post > Topic >>

Exposing globals as read-only

by Ark Khasin <akhasin@[EMAIL PROTECTED] > Mar 10, 2008 at 02:19 AM

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

--
Thank you,
Ark
 




 16 Posts in Topic:
Exposing globals as read-only
Ark Khasin <akhasin@[E  2008-03-10 02:19:49 
Re: Exposing globals as read-only
Falcon Kirtaran <falco  2008-03-09 21:23:17 
Re: Exposing globals as read-only
Ark Khasin <akhasin@[E  2008-03-10 03:32:53 
Re: Exposing globals as read-only
Ian Collins <ian-news@  2008-03-10 17:35:14 
Re: Exposing globals as read-only
Shri <shri.gajare@[EMA  2008-03-09 22:57:57 
Re: Exposing globals as read-only
Ark Khasin <akhasin@[E  2008-03-10 06:09:26 
Re: Exposing globals as read-only
Ian Collins <ian-news@  2008-03-10 19:15:41 
Re: Exposing globals as read-only
Ark Khasin <akhasin@[E  2008-03-10 06:21:59 
Re: Exposing globals as read-only
Ark Khasin <akhasin@[E  2008-03-10 06:06:06 
Re: Exposing globals as read-only
Ian Collins <ian-news@  2008-03-10 19:16:47 
Re: Exposing globals as read-only
Ark Khasin <akhasin@[E  2008-03-10 06:19:38 
Re: Exposing globals as read-only
Ian Collins <ian-news@  2008-03-10 19:51:22 
Re: Exposing globals as read-only
Falcon Kirtaran <falco  2008-03-10 00:57:39 
Re: Exposing globals as read-only
richard@[EMAIL PROTECTED]  2008-03-10 10:48:13 
Re: Exposing globals as read-only
Ben Bacarisse <ben.use  2008-03-10 11:37:46 
Re: Exposing globals as read-only
Jack Klein <jackklein@  2008-03-10 21:33:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Sep 4 23:46:52 CDT 2008.