Weird behaviour with structs and the = operand

Post: #1
I a bit of code I've been writing I've got some structs. (Normally I use classes, but this code is in c and not c++.)

And at one point in my code I have code like this (simplified to shorten explanation):

typedef struct {
int a;
int b;
float c[3];
float d;
int e;

ITEM big_array[1000];

void thingy() {
ITEM temp;
temp = big_array[245]; // grab something from stack
// modify it
big_array[245] = temp; // put it back on the stack

But not everything gets shunted on and off the stack correctly. I realize arrays like 'c' should not, but some values like 'd' and 'e' just don't for some reason. What I mean is, when I use '=' to transfer the structs values a and b might copy but d and e won't. It's weird, because it's always the same items in the struct but they appear to be initially chosen at random. I'm not sure why.

I'm gonna make a function to copy my structs, but I'm curious why this is happening.

Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #2
There's nothing inherently wrong with the code you've posted. The assign will do an exact bitwise copy (likely actually call memcpy with a struct that large). Even the content of C will be copied, since no pointers are involved.
Quote this message in a reply
Post: #3
Weird, I must have modified my values wrong or something.

Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Drawing an OBJ from structs mikey 51 17,113 Jul 13, 2009 09:23 AM
Last Post: mikey
  Confused as to array behaviour kendric 3 2,327 Mar 14, 2009 05:26 PM
Last Post: kendric
  Free Structs Justin Brimm 4 3,461 May 30, 2006 06:20 AM
Last Post: Jones