Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

why do field names include the struct name?

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


davem at iabyn

May 21, 2012, 1:37 AM

Post #1 of 3 (64 views)
Permalink
why do field names include the struct name?

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.
If this is the case, is there any good reason to follow this convention
for new structs? From either a technical or stylistic viewpoint.

--
A major Starfleet emergency breaks out near the Enterprise, but
fortunately some other ships in the area are able to deal with it to
everyone's satisfaction.
-- Things That Never Happen in "Star Trek" #13


fawaka at gmail

May 21, 2012, 2:06 AM

Post #2 of 3 (64 views)
Permalink
Re: why do field names include the struct name? [In reply to]

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.
> 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.

Leon


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

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.