struct problems

This is a discussion on struct problems within the C Programming forums, part of the General Programming Boards category; Please help me work out why This struct works Code: /* hashStruct */ struct test { List hashTable[MAXTABLE]; int secondVariable; ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    18

    Exclamation struct problems

    Please help me work out why
    This struct works
    Code:
    /* hashStruct */
    struct test
    {
        List hashTable[MAXTABLE];
        int secondVariable;
    };
    typedef struct test hashStruct;
    And this struct works
    Code:
    struct myStruct
    {
       char *fileName;
       char instanceName[MAX_LENGTH];
       int customers;
       int products;
       int lowerBound;
       int upperBound;
       int TotalSegments;
       int matrix[MAX_CUSTOMERS][MAX_PRODUCTS];
       Product productArray[MAX_PRODUCTS];
    
       /* flags section */
       int maxIterations;
       bool verbose;
       bool elimSubsumed;
       bool partition;
       bool completeMOSP;
       bool print;
       bool branchAndBound;
       bool aStarOriginal;
       bool aStarStepwise;
       bool aStarBackwards;
       bool aStarBinaryChop;
       bool Heuristic_TrivialBounds;
    };
    typedef struct myStruct mospData;
    yet
    Code:
    struct myStruct
    {
       char *fileName;
       char instanceName[MAX_LENGTH];
       int customers;
       int products;
       int lowerBound;
       int upperBound;
       int TotalSegments;
       int matrix[MAX_CUSTOMERS][MAX_PRODUCTS];
       Product productArray[MAX_PRODUCTS];
       List hashTable[MAXTABLE];                    // this is the different line (line 50)
    
       /* flags section */
       int maxIterations;
       bool verbose;
       bool elimSubsumed;
       bool partition;
       bool completeMOSP;
       bool print;
       bool branchAndBound;
       bool aStarOriginal;
       bool aStarStepwise;
       bool aStarBackwards;
       bool aStarBinaryChop;
       bool Heuristic_TrivialBounds;
    };                                             // (line 65)
    typedef struct myStruct mospData;
    Gives me this message when i compile
    50: error: syntax error before 'List'
    50: warning: no semicolon at end of struct or union
    65: error: syntax error before '}' token
    I just don't get, it must be a syntax thing but i can't work it out.
    Please help!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Where is 'List' defined?


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

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    18
    These are the other structs in the program
    Code:
    struct LinkedListRec
    {
       int    count;
       Node*  headPtr;
    };
    typedef struct LinkedListRec List;
    
    struct NodeRec
    {
       Set set;
       int activeStacks;
       struct NodeRec* nextPtr;
    };
    typedef struct NodeRec Node;
    
    
    /* the Structs required in Node */
    struct setStruct
    {
       bitArray value;
       int setSize;
    };
    typedef struct setStruct Set;
    
    struct bitwiseArray
    {
        unsigned long long high;
        unsigned long long low;
    };
    typedef struct bitwiseArray bitArray;
    NOTE that the struct below works and if i can't get it to work inside the mospData struct it is likely how i will use it, however i want to understand what is happening
    Code:
    struct test
    {
        List hashTable[MAXTABLE];
        int secondVariable;
    };
    typedef struct test hashStruct;

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    Are you just going to keep copy / pasting bits of structs out of context, or are you going to post a complete unedited example of what does not compile?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting from C to C++
    By Taka in forum C++ Programming
    Replies: 5
    Last Post: 04-08-2009, 02:16 AM
  2. Replies: 1
    Last Post: 12-03-2008, 02:10 AM
  3. weird typedef struct problems
    By olidem in forum C Programming
    Replies: 3
    Last Post: 07-28-2008, 02:59 PM
  4. 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
  5. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM

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