Automatic variables in external structure definition

This is a discussion on Automatic variables in external structure definition within the C Programming forums, part of the General Programming Boards category; Say I put a character array of the form "char variable[SIZE]" in the definition of an external structure. How is ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    54

    Automatic variables in external structure definition

    Say I put a character array of the form "char variable[SIZE]" in the definition of an external structure.

    How is the initialization/destruction of the array handled with relation to the creation/destruction of objects of this structure type?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Every object has an array in it, so the array is created when the object is created and destroyed when the object is destroyed. That is, the scope of every member of the object is the same as the scope of the object.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    In C there's no "constructor/destructor" concept. An array in a struct will be set to zero on global & static variables, and random values (whatever happens to be on the stack/heap location where it ends up) in any other situation.

    --
    Mats
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 02:29 PM
  2. VC++ a POS
    By Welder in forum Windows Programming
    Replies: 40
    Last Post: 11-07-2007, 03:07 PM
  3. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  4. function definition with structure node
    By Peachy in forum C Programming
    Replies: 2
    Last Post: 12-10-2001, 10:49 PM
  5. referencing structure variables
    By sballew in forum C Programming
    Replies: 1
    Last Post: 11-01-2001, 01:56 PM

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