Problem referencing structure elements by pointer

This is a discussion on Problem referencing structure elements by pointer within the C Programming forums, part of the General Programming Boards category; If the typedef is visible, that's fine -- you just need to call it "configurationOptions" (since that's the name you ...

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If the typedef is visible, that's fine -- you just need to call it "configurationOptions" (since that's the name you gave it in the typedef) instead of "struct configurationsOptions".

    Edit to add: At this point, I would say, if you have most of your code referring to "struct configurationOptions" to not typedef it but make it a named struct; if it's just a few mentions, go ahead and change those mentions. There's no advantage either way (typedef vs. named struct), so do whatever causes the least amount of typing at this point.

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,167
    Anonymous means it simply doesn't have a name - nothing more.
    Again, remove the "struct" keyword because there is no struct named configurationsOptions. There is only something named configurationsOptions.
    As long as you have a full declaration of the struct, you can do a sizeof on it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  3. #18
    Registered User
    Join Date
    May 2008
    Posts
    28
    Many thanks - all clear now and code working

  4. #19
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    I wouldn't recommend typedef'ing it the same as the struct name,

    I tend to do, along with a lot of other people
    Code:
    typedef struct name_s
    {
    
    } name_t;
    That way you know, name_t is a type, and name_s is a struct.
    Last edited by zacs7; 06-13-2008 at 07:29 PM.

  5. #20
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Note that there's nothing actually wrong with using the same name for the structure as you do for the typedef, it's just rather confusing.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  3. accessing structure pointer problem
    By godhand in forum C Programming
    Replies: 2
    Last Post: 04-09-2004, 10:52 PM
  4. Pointer to structure problem
    By unregistered in forum C Programming
    Replies: 3
    Last Post: 12-24-2001, 06:54 AM
  5. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 04:48 PM

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