How is this useful ???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hotadvice

    How is this useful ???

    hi all

    I was just browsing some code(actually apache)

    and i found this :

    typedef struct apr_pool_t apr_pool_t

    How this is usefull??


    Thanx in advance

    Aman Aggarwal

  • Richard Bos

    #2
    Re: How is this useful ???

    "hotadvice" <aman.coe@gmail .com> wrote:
    [color=blue]
    > typedef struct apr_pool_t apr_pool_t
    >
    > How this is usefull??[/color]

    Erm... it defines a type alias for a struct type? How else would it be
    useful? It means that instead of referring to that type as struct
    apr_pool_t, you can now do so using just apr_pool_t. Saves a whole
    whopping seven characters. Personally, I never bother unless I want to
    hide the underlying type, but there are those who prefer this.

    Richard

    Comment

    • Zara

      #3
      Re: How is this useful ???

      On 28 Oct 2005 04:57:16 -0700, "hotadvice" <aman.coe@gmail .com> wrote:
      [color=blue]
      >hi all
      >
      >I was just browsing some code(actually apache)
      >
      >and i found this :
      >
      >typedef struct apr_pool_t apr_pool_t
      >
      >How this is usefull??
      >
      >
      >Thanx in advance
      >
      >Aman Aggarwal[/color]

      I'll be whipped for mentioning it, butusing this typedef you can write
      the rest of the references to this struct in a way compatible both to
      C and C++.

      Please, do not beat me too much for naing Satan in tthis Temple... ;-)

      Comment

      • Martin Ambuhl

        #4
        Re: How is this useful ???

        hotadvice wrote:
        [color=blue]
        > I was just browsing some code(actually apache)
        > and i found this :[/color]
        [color=blue]
        > typedef struct apr_pool_t apr_pool_t[/color]
        [color=blue]
        > How this is usefull??[/color]

        (Not at all without the missing semicolon.)
        It saves typing the characters 'struct ' in declarations of 'struct
        apr_pool_t' objects. If avoiding typing a few characters seems useful
        to you, then the typedef begins to be useful if you use this type more
        than 5 times (since typing the typedef itself must be offset).

        Comment

        • Dave Thompson

          #5
          Re: How is this useful ???

          On Fri, 28 Oct 2005 13:27:34 GMT, Zara <yozara@terra.e s> wrote:
          [color=blue]
          > On 28 Oct 2005 04:57:16 -0700, "hotadvice" <aman.coe@gmail .com> wrote:[/color]
          [color=blue][color=green]
          > >typedef struct apr_pool_t apr_pool_t[/color][/color]
          [color=blue]
          > I'll be whipped for mentioning it, butusing this typedef you can write
          > the rest of the references to this struct in a way compatible both to
          > C and C++.
          >[/color]
          Compatible with the usual and arguably preferred C++ style.

          C++ does (also) allow you to use the C-like form, which it calls an
          elaborated-type-specifier -- struct foo, class foo, union foo, or enum
          foo -- as well as just foo. And in name conflict cases that are
          arguably bad style anyway it requires it, as C always does.
          - David.Thompson1 at worldnet.att.ne t

          Comment

          Working...