
nick at ccl4
May 25, 2012, 7:20 AM
Post #3 of 3
(52 views)
Permalink
|
|
Re: why do field names include the struct name?
[In reply to]
|
|
On Mon, May 21, 2012 at 11:06:33AM +0200, Leon Timmermans wrote: > On Mon, May 21, 2012 at 10:37 AM, Dave Mitchell <davem [at] iabyn> wrote: > > Dumb C question: > > > > a lot of of the field names for our structs include the name of the struct > > as a prefix; e.g. the SV struct has a field called sv_refcnt. > > > > I have a vague recollection that this was required in pre-ANSI (K&R) C due > > to some problem with namespaces being shared, but is no longer required. I wasn't aware of this until recently. Perl is older than ANSI C89, and compilers often take a long time to completely implement standards. (or never. eg fflush(NULL), and a lot of C99 in quite a few compilers) Moreover, I suspect that the defensive habits learned while dealing with the foibles of the pre-standard compilers will last a lot longer. > > If this is the case, is there any good reason to follow this convention > > for new structs? From either a technical or stylistic viewpoint. > > I know it can be useful to redefine stuff. If sv_refcnt would become > part of some struct/union tomorrow we could maintain compatibility > with all other code using simply a «#define sv_refcnt > sv_foo.sv_refcnt». Not that that's particularly relevant to us, since > we tend to access everything through macros anyway. Both the C > standard and POSIX do this all of the time, so possibly it's just > following their style. This was my assumption. Nicholas Clark
|