Thread: structure tag required?

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    26

    structure tag required?

    Hello!

    Can somebody tell me is name tag for structures required? I tried to find the answer in my C book but i found nothing.

    Thanks.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That depends. If you want to create instances of it later, yes. Otherwise no.
    Code:
    struct
    {
        int x;
    } instance;
    
    instance.x = 10;
    The above is fine. However, you're unable to create other instances, because you have no way of referencing it:
    Code:
    struct __oops no name___ instance2; /* you have no name, so you can't */
    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Technically, this is also an unnamed struct except its reffered to as Point:
    Code:
    typedef struct { int x, y, z; } Point;
    What's really neat about the above is that you don't have to specify its a struct when you want to declare one. Note no struct keyword in the following:
    Code:
    Point p;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. C structure help required
    By coo_pal in forum C Programming
    Replies: 2
    Last Post: 01-23-2003, 01:40 PM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM