Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Debugging Problem with CHAR

Debugging Problem with CHAR

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RockNix
    wrote on last edited by
    #1

    Hi, I have problems filling up a structure while debugging. The Strucutre is something like this: typedef struct { char; // (8Bit) unsigned int; // (32Bit) somepointer*; // (32Bit) } what makes 9 Byte together. I want to fill up the struct with a byte-pointer pointing to a stream. That works but the problem is that in debugging mode CHAR seems to be 32Bit long, because when I fill up the struct byte by byte the first byte is placed into the CHAR but it needs 3 more bytes to get to the UNSIGNED INT. Any ideas ? Thanks! CU Mario /// ---------------------- www.klangwerker.de mario@klangwerker.de ----------------------

    L 1 Reply Last reply
    0
    • R RockNix

      Hi, I have problems filling up a structure while debugging. The Strucutre is something like this: typedef struct { char; // (8Bit) unsigned int; // (32Bit) somepointer*; // (32Bit) } what makes 9 Byte together. I want to fill up the struct with a byte-pointer pointing to a stream. That works but the problem is that in debugging mode CHAR seems to be 32Bit long, because when I fill up the struct byte by byte the first byte is placed into the CHAR but it needs 3 more bytes to get to the UNSIGNED INT. Any ideas ? Thanks! CU Mario /// ---------------------- www.klangwerker.de mario@klangwerker.de ----------------------

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The reason is byte packing. The i386 and later processors can access memory that is aligned or unaligned to specific boundaries. For byte size operations, any address is as good as another (not quite true, but its handled inside the processor). For word size (16 bit) operations, accesses are faster on 16 bit aligned addresses (every 2 bytes). For DWORD and pointer size operations, accesses are faster on 32 bit aligned addresses (every 4 bytes). Since your structure has a 4 byte sized object (the unsigned int) following the char it has been aligned to the next optimal address. If you really don't like this you can instruct the compiler how you want it to behave using the #pragma pack directive. Stephen Kellett

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups