structure member prefixes
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > structure member prefixes




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    structure member prefixes  
Frank Cusack


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-18-05 01:54 AM

The members of 'struct stat' begin with st_.  The members of 'struct timeval
'
begin with tv_.

What is the reason for this?

-frank





[ Post a follow-up to this message ]



    Re: structure member prefixes  
Jordan Abel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-18-05 01:54 AM

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





[ Post a follow-up to this message ]



    Re: structure member prefixes  
Don Morris


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-18-05 01:54 AM

Frank Cusack wrote:
> The members of 'struct stat' begin with st_.  The members of 'struct timev
al'
> 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





[ Post a follow-up to this message ]



    Re: structure member prefixes  
those who know me have no need of my name


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-18-05 07:49 AM

in comp.unix.programmer i read:

>The members of 'struct stat' begin with st_.  The members of 'struct timeva
l'
>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





[ Post a follow-up to this message ]



    Re: structure member prefixes  
SM Ryan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-18-05 07:49 AM

Frank Cusack <fcusack@fcusack.com> wrote:
# The members of 'struct stat' begin with st_.  The members of 'struct timev
al'
# 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.





[ Post a follow-up to this message ]



    Re: structure member prefixes  
Alex Fraser


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-18-05 12:50 PM

"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







[ Post a follow-up to this message ]



    Re: structure member prefixes  
Valentin Nechayev


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-18-05 12:50 PM


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 tim
eval'
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-





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:29 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register