Can someone simplify this statement from this thead

This is a discussion on Can someone simplify this statement from this thead within the C Programming forums, part of the General Programming Boards category; The original thread is from comp.lang.c. The URL of the thread is: http://groups.google.com/group/comp....d2cbc9d781c4cd Can someone clarify the following statement (maybe ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195

    Can someone simplify this statement from this thead

    The original thread is from comp.lang.c. The URL of the thread is:

    http://groups.google.com/group/comp....d2cbc9d781c4cd

    Can someone clarify the following statement (maybe with some corny example code). I'm just not making the connection.

    "I always seem to have problems with structures when they aren't typedef'd. When structures are typedef'd, you can cast values to structure elements and take the size of structure elements without actually having a valid, allocated, and filled data structure. For example, say you have three structures which should be nested but are separate. Now, you need some data
    from the third structure. But, you have a raw buffer that corresponds to the first structure, and, of course, contains the data for second and third structures. How do you get to the data in the third structure? Using typedef'd structures and casts, you can access the data from the third structure in the raw buffer without allocating space for or filling in the structures. You only need to allocate space for the raw buffer and variables which are assigned data from the third structure. You have total
    access to any data in the raw buffer, but you don't need to allocate and fill any intermediate structures. "


    Thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Typedef has nothing to do with the ability to do this. You can do anything without a typedef, that you can do with one. All a typedef does is make an alias to "struct foo" to "foo_t".


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 02:57 AM
  3. If Else statement problem
    By doofusboy in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 06:18 AM
  4. string & if statement
    By Curacao in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 09:56 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 03:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21