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. Serialization

Serialization

Scheduled Pinned Locked Moved C / C++ / MFC
jsonhelpquestion
6 Posts 4 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.
  • _ Offline
    _ Offline
    _Tom_
    wrote on last edited by
    #1

    Hi all, I have strange error during serialization. I do the following: ar << m_nTime; // (Value typically > 120000) ar << m_bFlag; // (type BOOL) and the m_bFlag always returns as 0; If I do the following: ar << m_nTime; int tmp; tmp = m_bFlag ? 1 : 0; ar << tmp; everything works fine. I'm certainly a little confused and if anyone has some ideas that would be great. Thanks Tom

    S B 2 Replies Last reply
    0
    • _ _Tom_

      Hi all, I have strange error during serialization. I do the following: ar << m_nTime; // (Value typically > 120000) ar << m_bFlag; // (type BOOL) and the m_bFlag always returns as 0; If I do the following: ar << m_nTime; int tmp; tmp = m_bFlag ? 1 : 0; ar << tmp; everything works fine. I'm certainly a little confused and if anyone has some ideas that would be great. Thanks Tom

      S Offline
      S Offline
      Sarath C
      wrote on last edited by
      #2

      _Tom_ wrote:

      ar << m_nTime; int tmp; tmp = m_bFlag ? 1 : 0; ar << tmp;

      it seems that you are trying to do this...

      int tmp;
      tmp = m_nTime ? 1 : 0; // depends on the time value you are setting flag
      ar << tmp;

      Im not sure whether i've answered you. if you explain, what you are trying to do will be more useful. SaRath.
      "It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar." My Blog | Understanding State Pattern in C++ -- modified at 6:59 Wednesday 28th June, 2006

      1 Reply Last reply
      0
      • _ _Tom_

        Hi all, I have strange error during serialization. I do the following: ar << m_nTime; // (Value typically > 120000) ar << m_bFlag; // (type BOOL) and the m_bFlag always returns as 0; If I do the following: ar << m_nTime; int tmp; tmp = m_bFlag ? 1 : 0; ar << tmp; everything works fine. I'm certainly a little confused and if anyone has some ideas that would be great. Thanks Tom

        B Offline
        B Offline
        bob16972
        wrote on last edited by
        #3

        I don't think BOOL is one of the data types supported by CArchive. I usually treat my BOOL types as a flag in a BYTE or DWORD when serializing or something to that effect.

        O 1 Reply Last reply
        0
        • B bob16972

          I don't think BOOL is one of the data types supported by CArchive. I usually treat my BOOL types as a flag in a BYTE or DWORD when serializing or something to that effect.

          O Offline
          O Offline
          ovidiucucu
          wrote on last edited by
          #4

          Much scraping for nothing. ;) BOOL is a type defined in WINDEF.H

          typedef int   BOOL;
          

          and CArchive has an operator

          CArchive& operator <<(int i);
          

          Ovidiu Cucu Microsoft MVP - Visual C++

          B 1 Reply Last reply
          0
          • O ovidiucucu

            Much scraping for nothing. ;) BOOL is a type defined in WINDEF.H

            typedef int   BOOL;
            

            and CArchive has an operator

            CArchive& operator <<(int i);
            

            Ovidiu Cucu Microsoft MVP - Visual C++

            B Offline
            B Offline
            bob16972
            wrote on last edited by
            #5

            Fair enough. I stand corrected. :( I guess because it wasn't in the MSDN list for CArchive, so I just assumed... Anyway, to save face, Serializing a BOOL (int) will take up 4 bytes in the file which can get excessive if there are many BOOL's in many objects. Storing as many of these as flags in BYTE's or DWORD's will prevent waste. Good day and thanks for the correction. :-D

            O 1 Reply Last reply
            0
            • B bob16972

              Fair enough. I stand corrected. :( I guess because it wasn't in the MSDN list for CArchive, so I just assumed... Anyway, to save face, Serializing a BOOL (int) will take up 4 bytes in the file which can get excessive if there are many BOOL's in many objects. Storing as many of these as flags in BYTE's or DWORD's will prevent waste. Good day and thanks for the correction. :-D

              O Offline
              O Offline
              ovidiucucu
              wrote on last edited by
              #6

              Sincerely, me personal, I wolud like to prefer wasting few bytes than wasting time and adding extra code. :) Although, that's not so big subject to argue... Have a nice day! Ovidiu

              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