|
|
|
|
|
|
|
In particular, local variables are frequently used to hold the values of variables passed via pointers to structures. This is done for two reasons: |
|
|
|
|
|
|
|
|
The intermediate variable is more legible. It is easier to read, understand and debug day than input_date>day. |
|
|
|
|
|
|
|
|
When the input variable is referenced repeatedly within the function, most compilers will generate faster code if the intermediate variable is used. Compilers for the PC, in particular, typically generate far pointers for each reference to the argument variable passed in a stack, so it is better to take the speed hit once with an assignment to a local variable. |
|
|
|
|
|
|
|
|
Pointers are often intimidating, especially to novices, and therefore are used sparingly and only when required to pass a structure to a function. A typical pointer usage would be the following function definition: |
|
|
|
|
|
|
|
|
double foo_date_to_JD0 (struct DATE_INFO *date); |
|
|
|
|
|
|
|
|
In general, the SCDTL system is ''tighter" than C with regard to its handling of types. |
|
|
|
|
|
|
|
|
All functions are explicitly declared by type. Defaults are not assumed. Type int functions are explicitly declared as such. |
|
|
|
|
|
|
|
|
The return statement is used in all functions, even where C does not require it. In particular, type void functions always contain return; statements. |
|
|
|
|
|
|
|
|
Type conversions are always explicitly coded for clarity and legibility. This convention eliminates an entire class of insidious bugs that find a niche in C code by virtue of its relatively weak typing. |
|
|
|
|
|
|
|
|
1.6.4
Consistency and Automation Considerations |
|
|
|
|
|
|
|
|
The overall goal with regard to conventions has been to choose and implement them with machine-like consistency. There are numerous advantages to this policy. The reusability of code is enhanced, and maintenance and testing tasks are correspondingly reduced. The generation of code can be automated by adhering to rules, rather than handicraft. The processing of code-checking, cross-referencing, searching, and so on is made simpler when strict rules are followed. Productivity is thereby enhanced. |
|
|
|
|
|
|
|
|
A standard set of two-character codes has been adopted for the purposes of identifying the source files for functions associated with different calendars (Table 1.3). |
|
|
|
|
|
|
|
|
In addition, a set of conventions has been adopted for identifying functions which serve similar purposes in different calendars (Table 1.4). The code xx denotes the standard two-character code for the calendar (Table 1.3). Table 1.5 lists the naming conventions. |
|
|
|
|
|
|
|
|
Thus, a filename such as JD02SYDT.C is easily identified as a conversion of a Julian Day number with assumed zero fractional part to an equivalent Syrian calendar date. |
|
|
|
|
|