magic_numbers revision 499b34cea04a46823d003d4c0520c8b03e8513cb
217f572018871cdf09db052a676b9933512cdbfaMark AndrewsCopyright (C) 1999-2001 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark AndrewsSee COPYRIGHT in the source root or http://isc.org/copyright.html for terms.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews$Id: magic_numbers,v 1.5 2001/01/09 21:47:01 bwelling Exp $
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark AndrewsMagic Numbers
217f572018871cdf09db052a676b9933512cdbfaMark AndrewsA number of data structures in the ISC and DNS libraries have an unsigned int
4be63b1fd8c18dbeca1648d6cf22fa14f057a469David Lawrencemagic number as the first field. The purpose of the magic number is
4be63b1fd8c18dbeca1648d6cf22fa14f057a469David Lawrenceprincipally to validate that a pointer a subroutine has gotten really points
4be63b1fd8c18dbeca1648d6cf22fa14f057a469David Lawrenceto the type it claims to be. This helps detect problems caused by resources
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updaterbeing freed prematurely, that have been corrupted, or that have not been
217f572018871cdf09db052a676b9933512cdbfaMark Andrewsproperly initalized. It can also be handy in debugging.
ab023a65562e62b85a824509d829b6fad87e00b1Rob AusteinMagic numbers should always be the first field. They never require locking
217f572018871cdf09db052a676b9933512cdbfaMark Andrewsto access. As to the actual value to be used, something mnemonic is good:
2e8215dda9e102355baca77e4e59132eff8e2357Mark Andrews #define TASK_MAGIC 0x5441534BU /* TASK. */
2e8215dda9e102355baca77e4e59132eff8e2357Mark Andrews #define VALID_TASK(t) ((t) != NULL && \
2e8215dda9e102355baca77e4e59132eff8e2357Mark Andrews (t)->magic == TASK_MAGIC)
4be63b1fd8c18dbeca1648d6cf22fa14f057a469David Lawrence #define TASK_MANAGER_MAGIC 0x54534B4DU /* TSKM. */
4be63b1fd8c18dbeca1648d6cf22fa14f057a469David Lawrence #define VALID_MANAGER(m) ((m) != NULL && \
Magic values are generally private to the implementation of the type. I.e.
Magic number checking may become a build option in a future release. E.g.