You are here: Elements > Methods > Common

Common

In your .MTH file you may include a common section. This usually goes at the top and contains anything you need to have there that is other than methods. The common section is the place to put general #includes ‐ that is for .h, .cpp or any other appropriate type of file other than an .MH which should be included outside the common section. A common section could also contain class, type and structure definitions, #defines, and so on. It is delimited by the keywords COMMON and ENDCOMMON as in this example taken from FTESTD.MTH.

COMMON

static int __SizeOfUnitsInBits__(int iUnits)

{

Significance

static int aiSize[] = { 1, 1, 1, 4, 4, 8, 8, 8, 8, 16, 16, 32, 32, 64, 64 };

if ((iUnits < 0) || (iUnits >= sizeof(aiSize)/sizeof(aiSize[0])))

return 0;

return aiSize[iUnits];

}

ENDCOMMON

Be careful with the common section. It is easy to misuse it and put code and variables in it that could better be put somewhere else. Think of it as equivalent to global data, and avoid using it more than necessary. In particular, although it is legal to do so, never declare variables in this section. Because methods get executed in unexpected ways, you can never be sure of a variable state you have declared. (See Chapter 9: Decoder Data Objects on page 116). If you are tempted to declare a variable here, you probably need to use the inter-frame data construct explained in Chapter 5.2. You can declare constants in this section without harm.