Results 1 to 2 of 2

Thread: doubt in c programming

  1. #1
    Join Date
    Oct 2007
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default doubt in c programming

    hi
    in the below file in dont know what to pass in const void *data in main.c.can u help
    void CrcUpdate(UInt32 *crc, const void *data, size_t size)

    Qt Code:
    1. /* 7zCrc.c */
    2.  
    3. #include "7zCrc.h"
    4.  
    5. #define kCrcPoly 0xEDB88320
    6.  
    7. UInt32 g_CrcTable[256];
    8.  
    9. void InitCrcTable()
    10. {
    11. UInt32 i;
    12. for (i = 0; i < 256; i++)
    13. {
    14. UInt32 r = i;
    15. int j;
    16. for (j = 0; j < 8; j++)
    17. if (r & 1)
    18. r = (r >> 1) ^ kCrcPoly;
    19. else
    20. r >>= 1;
    21. g_CrcTable[i] = r;
    22. }
    23. }
    24.  
    25. void CrcInit(UInt32 *crc) { *crc = 0xFFFFFFFF; }
    26. UInt32 CrcGetDigest(UInt32 *crc) { return *crc ^ 0xFFFFFFFF; }
    27.  
    28. void CrcUpdateByte(UInt32 *crc, Byte b)
    29. {
    30. *crc = g_CrcTable[((Byte)(*crc)) ^ b] ^ (*crc >> 8);
    31. }
    32.  
    33. void CrcUpdateUInt16(UInt32 *crc, UInt16 v)
    34. {
    35. CrcUpdateByte(crc, (Byte)v);
    36. CrcUpdateByte(crc, (Byte)(v >> 8));
    37. }
    38.  
    39. void CrcUpdateUInt32(UInt32 *crc, UInt32 v)
    40. {
    41. int i;
    42. for (i = 0; i < 4; i++)
    43. CrcUpdateByte(crc, (Byte)(v >> (8 * i)));
    44. }
    45.  
    46. void CrcUpdateUInt64(UInt32 *crc, UInt64 v)
    47. {
    48. int i;
    49. for (i = 0; i < 8; i++)
    50. {
    51. CrcUpdateByte(crc, (Byte)(v));
    52. v >>= 8;
    53. }
    54. }
    55.  
    56. void CrcUpdate(UInt32 *crc, const void *data, size_t size)
    57. {
    58. UInt32 v = *crc;
    59. const Byte *p = (const Byte *)data;
    60. for (; size > 0 ; size--, p++)
    61. v = g_CrcTable[((Byte)(v)) ^ *p] ^ (v >> 8);
    62. *crc = v;
    63. }
    64.  
    65. UInt32 CrcCalculateDigest(const void *data, size_t size)
    66. {
    67. UInt32 crc;
    68. CrcInit(&crc);
    69. CrcUpdate(&crc, data, size);
    70. return CrcGetDigest(&crc);
    71. }
    72.  
    73. int CrcVerifyDigest(UInt32 digest, const void *data, size_t size)
    74. {
    75. return (CrcCalculateDigest(data, size) == digest);
    76. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    Last edited by wysota; 12th November 2007 at 11:16. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: doubt in c programming

    But what is the problem? Are you aware what the above functions do? If so, you should have no problem in determining what to pass as an argument to each function. The "data" pointer should probably a pointer to a buffer containing the data to update the checksum with.

Similar Threads

  1. Doubt ?
    By Cutey in forum Qt Tools
    Replies: 2
    Last Post: 3rd March 2007, 10:45
  2. QT COM Programming
    By sarav in forum Newbie
    Replies: 5
    Last Post: 24th February 2007, 14:41
  3. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 12:04
  4. Model - View Programming doubt.
    By munna in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2006, 14:01
  5. MODEL/VIEW programming
    By mira in forum Newbie
    Replies: 3
    Last Post: 21st April 2006, 12:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.