CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Custom struct not working in C

    Quote Originally Posted by fiodis View Post
    That could be my problem. What's the purpose of the tag, then? MSDN says it could be used to refer to the structure type in code later, but why can't you just use the name of the type?
    'C' and C++ are two different languages. Hopefully you're not reading the rules for C++.

    For 'C', here are valid structs:
    Code:
    /* definition 1 */
    struct Vector
    { };
    
    /* definition 2 */
    typedef struct tagVector
    { } Vector;
    With 'C', the first definition requires you to declare Vector like this:
    Code:
    struct Vector myVector;
    I had to repeat using the keyword struct to declare the myVector variable.

    With the second definition, I can now do this, since the typedef was used:
    Code:
    Vector myVector;
    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; September 21st, 2012 at 08:05 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured