Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3409 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  struct et sizeof

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

struct et sizeof

n°193345
olivier__
Posté le 10-08-2002 à 09:59:08  profilanswer
 

Voilà, je ne comprends plus rien
 
je fait :

Code :
  1. struct TGAFileHeaderFormat
  2. {
  3. unsigned char IDLength;
  4. unsigned char ColorMapType;
  5. unsigned char ImageType;
  6. short FirstEntryIndex;
  7. short ColorMapLenght;
  8. unsigned char ColorMapEntrySize;
  9. short XOrigin;
  10. short YOrigin;
  11. short ImageWidth;
  12. short ImageHeight;
  13. unsigned char PixelDepth;
  14. unsigned char ImageDescriptor;
  15. };
  16. struct TGAFileHeaderFormat TGAFileHeader;
  17. int ee;
  18. ee=sizeof(TGAFileHeader);


J'obtiens ee=20 alors que normalement je devrais obtenir 18...
Mais si je retire short FirstEntryIndex; et short ColorMapLenght; j'obtiens bien 14...
Est ce quelqu'un sait pkoi ça fait ça?

mood
Publicité
Posté le 10-08-2002 à 09:59:08  profilanswer
 

n°193356
indice
Posté le 10-08-2002 à 11:31:12  profilanswer
 

mais ca avant ta struct :  
 
#pragma pack (push)
#pragma pack (1)
 
et ca apres :  
 
#pragma pack (pop)
 
 
Tu peux aussi utiliser l'option /Zp dans visual c++
 
 
Pour les explication : http://msdn.microsoft.com/library/ [...] R_pack.asp
 
 :hello:

n°193365
olivier__
Posté le 10-08-2002 à 11:43:48  profilanswer
 

Merci beaucoup indice,
J'avais vu l'histoire du /Zp, il était à 8 mais ça ne marchait pas...
Mais avec les #pragma, ça marche.
Merci encore

n°193369
olivier__
Posté le 10-08-2002 à 11:53:43  profilanswer
 

Rahh j'ai encore confondu byte et bit, il fallait mettre lz /Zp à 1, que je suis c.. parfois.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  struct et sizeof

 

Sujets relatifs
[C] On peut ajouter un constructeur à une struct?[C/C++]besoin d'aide pour les struct typedef struct etc....
Plus de sujets relatifs à : struct et sizeof


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)