CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: CRCs

  1. #1
    Join Date
    Aug 2019
    Posts
    72

    bundle data integrity

    Hi,
    Got structure DataStruct:
    Code:
    DataStruct d1;
    //fill d1; 
    FilldDataStruct((unsigned char*)&d1);
    CRC1=CrcOf((unsigned char*)d1);
    void (DataStruct * d)
    {
    CRC2=CrcOf((unsigned char*)d);
    
    
    }
    why CRC1 != CRC2?; How to make CRC1 and CRC2 the same?. DataStruct is packed.
    Last edited by @EE@; February 26th, 2023 at 02:40 PM.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: CRCs

    What is this supposed to do:

    Code:
    void (DataStruct * d)
    {
        CRC2=CrcOf((unsigned char*)d);
    }
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Aug 2019
    Posts
    72

    Re: CRCs

    meant to be a sudo code:

    Code:
    void VerifyAndCalcStat(DataStruct * d)
    {
    //DataStruct contains char strings and unsigned integers.
        CRC2=CrcOf((unsigned char*)d);
        
    .
    .
    .
    }
    Last edited by @EE@; February 21st, 2023 at 10:07 AM.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CRCs

    Quote Originally Posted by @EE@ View Post
    meant to be a sudo code:

    Code:
    void VerifyAndCalcStat(DataStruct * d)
    {
    //DataStruct contains char strings and unsigned integers.
        CRC2=CrcOf((unsigned char*)d);
        
    .
    .
    .
    }
    Where and how do you call this function?
    How and where do you compare CRC1 and CRC2?
    Victor Nijegorodov

  5. #5
    Join Date
    Aug 2019
    Posts
    72

    Re: CRCs

    traced the code,; somewhere before calling the VerifyAndCalcStat it was setting a field. Very tiny step. crc1 and crc2 seem to be the same and match. thanks for the hints.

    Code:
    unsigned int crc1, crc2;
    
    void exceute()
    {
         DataStruct d;
         fill_d(&d);
      
       
          //in here it was doing d.nm[60]=0;  //line x
          crc1 = crcOf(unsigned char*)d);  // moved these two before line x, now crc1 and crc2 match.
          VerifyAndCalcStat(&d);  
    
    }
    void VerifyAndCalcStat(DataStruct * d)
    {
    //DataStruct contains char strings and unsigned integers.
        CRC2=CrcOf((unsigned char*)d);
        in here c1c != crc2
    .
    .
    .
    }
    Last edited by @EE@; February 22nd, 2023 at 01:59 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured