Reputation: 409
I've been dropped on an existing project where the initial developer is no longer around and I don't have the experience of this guy.
So while revising the code, I've stumbled on a part where I see a defined magic number followed by a CRC.
...
// Fill the structure.
oFactoryParams.u16MagicNumber = PARAMMGR_EEPROM_MAGIC_NUMBER_FACTORY_PARAMS;
...
// Calculate CRC.
oFactoryParams.u16CRC = CRCUtilCompute(sizeof(oFactoryParams) - 2, u16Dummy, (UINT8*)&oFactoryParams);
// Write.
u32NbByte = NEEPROMWrite32Bit(...Some params...)
...
What is the use of this magic number? Is it related to the CRC?
Thank you
Upvotes: 0
Views: 728
Reputation: 8636
Magic numbers are commonly used to assert the type of a passed pointer in languages without RTTI to detect errors, connected with invalid typecasting, especially if parameters are passed as void*
.
CRC16 is usually used in legacy communication protocols for validating the data integrity after being sent through serial lines.
So I can image situation your structure is sent directly to socket/tty with send(s, &val, sizeof(val));
and in this case CRC16
could be useful.
So to conclude, these fields could be used for asserts/checks on different levels
Upvotes: 2