Author Topic: structs in c causing big size diffrences.  (Read 3736 times)

0 Members and 1 Guest are viewing this topic.

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
structs in c causing big size diffrences.
« on: February 26, 2008 »
Hi!
I can't understand one thing. I've been writing a small program, and at one point i needed to use a struct more. Merely by adding it, and doing a single instruction using it the size jumped by 1.5kb uncompressed. I disassembled 2 versions, one with this single instruction one without. the asm code differed very slightly. ( ~12 lines in ~2k lines were different )

So, if the code doesn't differ, why am i getting such a huge change?

Code: [Select]
typedef struct Primitive_
{
  unsigned int type;
  float pos[ 3 ], col[ 3 ];
  float rotx, roty;
  union
  {
     float sphere;
     float cube[ 3 ];
  };
} Primitive;

Code: [Select]
Primitive prim[ PRIMITIVENUM ];
(...)
sub( vector1, prim[ id ].pos, vector2 ); //this line adds 1.5kb, sub is also called previously on different vectors
Stripping the contents of Primitive doesn't reduce size.
Nananan.

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: structs in c causing big size diffrences.
« Reply #1 on: February 27, 2008 »
How big is PRIMITIVENUM?
Say around 50?

Thats your 1.5k there.

--
DBF debugging service.
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: structs in c causing big size diffrences.
« Reply #2 on: February 27, 2008 »
#define PRIMITIVENUM 2
:)
changing to 10000 makes no size difference. ( all arrays are in .bss section )

edit: mistake, it causes diffrence.
But that what is surpricing that the difference is between PRIMITIVEMNUM beeing 2 and 3. What the hell? ( even if no code uses the array! )

edit2: it is even more werid. For purpouses of finding why i have such problem i have commented out the rest of the function. I tried compiling with -Os, and the size dropped greatly, now there is no jump on primnum 2 to 3. That what is interesting that by uncommenting the rest of function i get ~1.5kb again but, with -O2 i don't get 2x 1.5 kb but only 1x1.5kb. The uncommented part gives sixty-something byte diffrence in file size if used with -O2.

So the file size doesn't differ to much with -O2/-Os, but it has a werid growth when (un)commenting :).


edit3: don't ask me :). I've switched computers and now no werid behaviour. At home everything's ok :).
« Last Edit: February 27, 2008 by frea »
Nananan.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: structs in c causing big size diffrences.
« Reply #3 on: February 27, 2008 »
Maybe depending on size the compiler is bringing in a library routine like memcpy or mul to do some internal sums instead of doing them inline?  But it sounds like your problem has gone away for now :)
Jim
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: structs in c causing big size diffrences.
« Reply #4 on: February 27, 2008 »
It seems that the compiler at labs is somewhat broken :p. I comment ~30 function calls and get 20bytes less uncompressed, although it ereases ~100 lines of asm.
Nananan.