Thread: Quick struct question

  1. #1
    Registered User
    Join Date
    Apr 2007

    Quick struct question

    is this code valid?
    where intA is 0 - will this create a new structure called newStruct1?
    struct appA newStruct[intA + 1];

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    If intA is a constant, then it's valid to do that. It will not so much "create a new struct" as make an array with one element of such structs - that may well be what you meant, but creating a new struct [in the way I'd use those words] means to create a different struct, not create an instance of an existing struct.

    If intA is not a constant, then you are relying on compiler extensions to achieve this, and it's not standard compliant. If the compiler accepts it, and intA has a defined value at the point where this code occurs, it will work, but it won't necessarily compile with a different compiler.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    It's valid in C99 constant or not, it will create an array with intA + 1 elements called newStruct. Not a variable called newStruct1

  4. #4
    Registered User
    Join Date
    Apr 2007
    Thanks for the replies. More to the point, see my latest post...

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. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  3. struct question
    By black_spot1984 in forum C Programming
    Replies: 5
    Last Post: 12-09-2006, 02:13 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. struct question...
    By Cheeze-It in forum C Programming
    Replies: 3
    Last Post: 11-07-2001, 06:28 AM