Structures and Unions Question. 
Author Message
 Structures and Unions Question.

Consider the following type defenitions:

typedef union {
  char str[20];
  long longnum;

Quote:
} SomeUnion;

typedef struct {
  SomeUnion un;
  int next;

Quote:
} SomeStruct;

and consider the following code segment:

  SomeStruct mystruct, yourstruct;

  strcpy (mystruct.un.str, "Hello world.");
  mystruct.next = 55;
  yourstruct = mystruct;

Will the assignment of one structure to the other COPY all of the string
in mystruct.un.str to yourstruct.un.str, plus the copying of the integer
next?  

Let me ask this general question:  When assigning a structure or a union
to another structure or union respectively, will all the information in
the structure or union be transfered to the other structure or union?  In
other words, will arrays be copied from structure to structure by a simple
assignment.  

Sorry for the spagetti question asking method.

/----------------------------------------------------------------------------\
|                                          | /====\  |     |   /===\  |    | |
|    The meek has indeed                   | |    |  |     |  /     ) |    | |
|                                          | |====/  |     |  \       |____| |
|                 inherited the Earth...   | |   \   |     |    \     |    | |
|__________________________________________| |    \  |     | (    \   |    | |

\----------------------------------------------------------------------------/



Sun, 21 Jan 1996 09:01:58 GMT  
 Structures and Unions Question.

Quote:

>Will the assignment of one structure to the other COPY all of the string
>in mystruct.un.str to yourstruct.un.str, plus the copying of the integer
>next?  

>Let me ask this general question:  When assigning a structure or a union
>to another structure or union respectively, will all the information in
>the structure or union be transfered to the other structure or union?  In
>other words, will arrays be copied from structure to structure by a simple
>assignment.  

Yes.

ben last



Tue, 23 Jan 1996 15:09:50 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Question regarding unions and structures

2. fread w/ Union structures

3. Structures vs. Unions

4. Initialising Union members of Structures

5. Bit-fields, unions and structures...

6. structure, union & enumeration tags

7. help: unnamed unions within structures

8. Union within structures

9. Alignment of data in a Structure/Union

10. structure union mess

11. Problems with structure+union

12. Structures & Unions

 

 
Powered by phpBB® Forum Software