Re: How can gcc generate crc value for a structure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19/12/2023 10:56, Tao.Zeng--- via Gcc-help wrote:
Dear GCC-HELP:

     I am look for if there is a command which can generate CRC of a structure by GCC.
     My problem is that there is a data structure used to pass paramters from one binary to another binary. They have same definition but in different header files. These files are put in differerent folder and build for different binaries. Once somebody changed it's definition in file A but fogot do same change in file B, then the data parameters are not match, and the problems is hard to check. So I want to know if there is any GCC command which can generate a crc or any other characteristic value which I can stored in each binary and check characteristic value/crc first before using them, so we can detect errors at first time.
     Could you help me for this problem? Thanks.


You are trying to get some kind of checksum of source code here? That is not something you will get within GCC.

The best solution for you will depend on your build systems and your development structure. Probably the best idea is to put the structure definition, and any other common features, in a /single/ dedicated header that is included by the files for both binaries.

If I am working with different programs that have to match on a particular data structure, I put a version number for the structure in the code. When I change the structure, I change the version number. At run time, if one program wants to exchange data with the other via this structure, they first compare structure version numbers. This lets things work (to at least some extent) even if the two sides of the exchange are separate and perhaps different generations of the software.

If you really need to checksum source code, it must be handled by your build system somehow. Maybe you could have a "makefile" rule that runs md5sum on the file, and passes it through a sed filter to generate another header file with a checksum stamp macro that you can check? Or use "diff" or "cmp" to compare the files as part of the build process, failing if they differ?

I think this is all well out of scope for the compiler.






[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux