Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. typedef struct <-> struct

typedef struct <-> struct

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Konrad Windszus
    wrote on last edited by
    #1

    What's the difference between typedef struct _MYSTRUCT { int nValue; DWORD dwValue2; }MYSTRUCT; and struct MYSTRUCT { int nValue; DWORD dwValue2; }; With each of them I can instantiate variables of type MYSTRUCT like: MYSTRUCT myStruct; And I doesn't need the old C style: struct MYSTRUCT myStruct; So why should I use typedef combined with struct. Are there any advantages or disadvantages. Thanks for any comment. Konrad

    T R 2 Replies Last reply
    0
    • K Konrad Windszus

      What's the difference between typedef struct _MYSTRUCT { int nValue; DWORD dwValue2; }MYSTRUCT; and struct MYSTRUCT { int nValue; DWORD dwValue2; }; With each of them I can instantiate variables of type MYSTRUCT like: MYSTRUCT myStruct; And I doesn't need the old C style: struct MYSTRUCT myStruct; So why should I use typedef combined with struct. Are there any advantages or disadvantages. Thanks for any comment. Konrad

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      you're not obiged to... the reason some code use this, it is because C don't allow to use types without the struct identifier, or when your struct is typedefed... In C++, it is only a portability reason...

      TOXCCT >>> GEII power

      1 Reply Last reply
      0
      • K Konrad Windszus

        What's the difference between typedef struct _MYSTRUCT { int nValue; DWORD dwValue2; }MYSTRUCT; and struct MYSTRUCT { int nValue; DWORD dwValue2; }; With each of them I can instantiate variables of type MYSTRUCT like: MYSTRUCT myStruct; And I doesn't need the old C style: struct MYSTRUCT myStruct; So why should I use typedef combined with struct. Are there any advantages or disadvantages. Thanks for any comment. Konrad

        R Offline
        R Offline
        Robert A T Kaldy
        wrote on last edited by
        #3

        In a good old C, you can use structures only with the keyword struct. In C++, the only advantage of using typedef is, that you write the struct name with one word :). In your example, MYSTRUCT is an alias to struct _MYSTRUCT. Robert-Antonio "Czech Railways discovered, that in case of disaster the most damaged wagons were the first and the last. So they decided to create trains without them."

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups