problem understanding c code

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

    #1

    problem understanding c code

    hi

    i'm going to develope an mp3 encoder and therefor i'm studiing the source
    code of lame mp3 encoder. but i'm not able to anderstand the nixt three
    lines of the sourde.

    struct lame_global_str uct;
    typedef struct lame_global_str uct lame_global_fla gs;
    typedef lame_global_fla gs *lame_t;

    maybe you can tell me how it works.

    thank you
    andi
  • Spiros Bousbouras

    #2
    Re: problem understanding c code

    On Nov 14, 11:56 am, Andreas <a.kas...@kabsi .atwrote:
    hi
    >
    i'm going to develope an mp3 encoder and therefor i'm studiing the source
    code of lame mp3 encoder. but i'm not able to anderstand the nixt three
    lines of the sourde.
    >
    struct lame_global_str uct;
    typedef struct lame_global_str uct lame_global_fla gs;
    typedef lame_global_fla gs *lame_t;
    The 2nd line defines "lame_global_fl ags" to be a name
    for the type "struct lame_global_str uct" and the 3rd
    line defines "lame_t" to be a name for the type "pointer
    to lame_global_fla gs". In other words lame_t is a name
    for the type "pointer to struct lame_global_str uct".

    Comment

    • Andreas

      #3
      Re: problem understanding c code

      and the fist line? what means it? - no structure of the datatype is
      defined?

      struct lame_global_str uct;




      Am Wed, 14 Nov 2007 12:03:54 +0000 schrieb Spiros Bousbouras:
      On Nov 14, 11:56 am, Andreas <a.kas...@kabsi .atwrote:
      >hi
      >>
      >i'm going to develope an mp3 encoder and therefor i'm studiing the
      >source code of lame mp3 encoder. but i'm not able to anderstand the
      >nixt three lines of the sourde.
      >>
      >struct lame_global_str uct;
      >typedef struct lame_global_str uct lame_global_fla gs; typedef
      >lame_global_fl ags *lame_t;
      >
      The 2nd line defines "lame_global_fl ags" to be a name for the type
      "struct lame_global_str uct" and the 3rd line defines "lame_t" to be a
      name for the type "pointer to lame_global_fla gs". In other words lame_t
      is a name for the type "pointer to struct lame_global_str uct".

      Comment

      • Mark Bluemel

        #4
        Re: problem understanding c code

        Spiros Bousbouras wrote:
        On Nov 14, 11:56 am, Andreas <a.kas...@kabsi .atwrote:
        >hi
        >>
        >i'm going to develope an mp3 encoder and therefor i'm studiing the source
        >code of lame mp3 encoder. but i'm not able to anderstand the nixt three
        >lines of the sourde.
        >>
        >struct lame_global_str uct;
        >typedef struct lame_global_str uct lame_global_fla gs;
        >typedef lame_global_fla gs *lame_t;
        >
        The 2nd line defines "lame_global_fl ags" to be a name
        for the type "struct lame_global_str uct" and the 3rd
        line defines "lame_t" to be a name for the type "pointer
        to lame_global_fla gs". In other words lame_t is a name
        for the type "pointer to struct lame_global_str uct".
        Which the OP could have found out by opening his C reference text.

        I suspect his question is really about the declaration of the "opaque"
        structure...

        This is a common technique in interface design, when a subsystem needs
        to be passed a (pointer to a) structure but we don't want the users of
        the subsystem to be aware of its composition.

        I would expect users of lame to only really work with lame_t data -
        pointers to structures, but we don't know (or care) what the structures
        looks like.

        Comment

        • Ben Bacarisse

          #5
          Re: problem understanding c code

          Andreas <a.kasper@kabsi .atwrites:
          Am Wed, 14 Nov 2007 12:03:54 +0000 schrieb Spiros Bousbouras:
          >On Nov 14, 11:56 am, Andreas <a.kas...@kabsi .atwrote:
          >>i'm going to develope an mp3 encoder and therefor i'm studiing the
          >>source code of lame mp3 encoder. but i'm not able to anderstand the
          >>nixt three lines of the sourde.
          >>>
          >>struct lame_global_str uct;
          >>typedef struct lame_global_str uct lame_global_fla gs;
          >>typedef lame_global_fla gs *lame_t;
          >>
          >The 2nd line defines "lame_global_fl ags" to be a name for the type
          >"struct lame_global_str uct" and the 3rd line defines "lame_t" to be a
          >name for the type "pointer to lame_global_fla gs". In other words lame_t
          >is a name for the type "pointer to struct lame_global_str uct".
          >
          and the fist line? what means it? - no structure of the datatype is
          defined?
          Please don't top post.
          struct lame_global_str uct;
          It says that there is a struct called lame_global_str uct and no more.
          It is used when the programmer wants to talk about a structure without
          saying anything more about it. In the example above, the programmer
          wants to define a synonym for the structure type and for a pointer to
          it. There is not much else you can do with it which is sometimes the
          whole purpose (look up "opaque types").

          There is no need to write it out like that.

          typedef struct lame_global_str uct lame_global_fla gs;
          typedef lame_global_fla gs *lame_t;

          serves the same purpose (in C). The original may have been written
          because, to a C++ compiler, a structure tag is a legal type name and
          the code may have once have had things like:

          some_function(l ame_global_stru ct *sp);

          in it once, or simply the author may have adopted that style because
          he/she is used to it from C++.

          --
          Ben.

          Comment

          Working...