|
Home > Archive > Unix Programming > November 2005 > structure member prefixes
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
structure member prefixes
|
|
| Frank Cusack 2005-11-17, 8:54 pm |
| The members of 'struct stat' begin with st_. The members of 'struct timeval'
begin with tv_.
What is the reason for this?
-frank
| |
| Jordan Abel 2005-11-17, 8:54 pm |
| On 2005-11-18, Frank Cusack <fcusack@fcusack.com> wrote:
> The members of 'struct stat' begin with st_. The members of 'struct
> timeval' begin with tv_.
>
> What is the reason for this?
Historical reasons. Struct members at one time did not have their
namespace, or were all in one namespace.
At least, this is my understanding.
>
> -frank
| |
| Don Morris 2005-11-17, 8:54 pm |
| Frank Cusack wrote:
> The members of 'struct stat' begin with st_. The members of 'struct timeval'
> begin with tv_.
>
> What is the reason for this?
So that structures with common field names (like cnt, for example) can
have those fields distinct enough for searches with tools like cscope,
etc. to be meaningful. st_cnt vs. tv_cnt, etc. Otherwise -- imagine
searching for all lines of code in a large project (like LibC or a
Unix kernel) for all modifiers of "cnt".
It isn't strictly needed, but it is a good convention -- and
abbreviating the root structure name is good for clarity.
Don
| |
| those who know me have no need of my name 2005-11-18, 2:49 am |
| in comp.unix.programmer i read:
>The members of 'struct stat' begin with st_. The members of 'struct timeval'
>begin with tv_.
>
>What is the reason for this?
in the old days member names lived in the normal namespace, instead of one
private to that structure.
--
a signature
| |
| SM Ryan 2005-11-18, 2:49 am |
| Frank Cusack <fcusack@fcusack.com> wrote:
# The members of 'struct stat' begin with st_. The members of 'struct timeval'
# begin with tv_.
#
# What is the reason for this?
If you #define mode, it won't corrupt the struct stat.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
So basically, you just trace.
| |
| Alex Fraser 2005-11-18, 7:50 am |
| "those who know me have no need of my name" <not-a-real-address@usa.net>
wrote in message news:m1sltuu0io.gnus@usa.net...
> in comp.unix.programmer i read:
>
> in the old days member names lived in the normal namespace, instead of
> one private to that structure.
I thought there was a namespace for all struct members, but separate from
normal identifiers. So the compiler would have a single mapping of
member_name -> (type, offset).
Alex
| |
| Valentin Nechayev 2005-11-18, 7:50 am |
|
Thu, Nov 17, 2005 at 16:41:25, fcusack (Frank Cusack) wrote about "structure member prefixes":
FC> The members of 'struct stat' begin with st_. The members of 'struct timeval'
FC> begin with tv_.
FC> What is the reason for this?
First, it is because early K&R C hadn't separate field name namespaces
for each structure; this was global namespace.
Second, it is often kept now because it is very convenient in some
cases. E.g. if different structures has tv_flags, st_flags, ic_flags
and so on, one can find all places where such field is used using
simple grep. In text where all such fields are named simply `flags',
smart code browser is required.
-netch-
|
|
|
|
|