MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | NAME |
| 2 | pragma |
| 3 | |
| 4 | DESCRIPTION |
| 5 | The preprocessor directive #pragma can be used to select |
| 6 | several compilation options. Multiple options can be selected |
| 7 | in one #pragma directive by separating them with commas. |
| 8 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 9 | no_inherit: The program can't be inherited. |
| 10 | no_shadow: The program can't be shadowed (similar to declaring |
| 11 | all functions as 'nomask'). |
| 12 | |
Zesstra | 5481d49 | 2021-04-08 20:07:06 +0200 | [diff] [blame] | 13 | clone: The blueprint object can be cloned (default, implies |
| 14 | no_lightweight). |
| 15 | no_clone: The blueprint object can't be cloned. |
| 16 | |
| 17 | lightweight: Lightweight objects may be created from the |
| 18 | blueprint (implies no_clone and warn_lightweight). |
| 19 | no_lightweight: Lightweight object cannot be created from it |
| 20 | (default). |
| 21 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 22 | init_variables: Clone variables are initialized by __INIT(). |
| 23 | share_variables: Clone variables are initialized from the |
| 24 | blueprint. |
| 25 | |
Zesstra | 3085c66 | 2025-08-02 18:31:10 +0200 | [diff] [blame] | 26 | no_simul_efuns: Disable the use of simul-efuns. This pragma |
| 27 | raises a privilege_violation("no_simul_efuns"). |
| 28 | simul_efuns: Enables the use of simul-efuns (this is the |
| 29 | default for all objects except the master). |
| 30 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 31 | weak_types: no type checking (this is the default). |
| 32 | strict_types: all functions must be declared with argument |
| 33 | prototypes, and the return values of call_other() must |
| 34 | be casted. |
| 35 | strong_types: all functions must be declared with complete |
| 36 | types of return value and parameters. |
| 37 | save_types: the declaration data is kept after compilation and |
| 38 | checked at runtime. This is important for type-safe |
| 39 | inheritance. |
Zesstra | 7ea4a03 | 2019-11-26 20:11:40 +0100 | [diff] [blame] | 40 | no_bytes_type: removes the keyword 'bytes', also 'string' then |
| 41 | denotes the type <string|bytes>. |
| 42 | bytes_type: reactivates the keyword 'bytes' and distinguishes |
| 43 | between the 'bytes' and 'string' type. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 44 | |
| 45 | rtt_checks: runtime checks during execution of this program will be |
Zesstra | 7ea4a03 | 2019-11-26 20:11:40 +0100 | [diff] [blame] | 46 | enabled. The interpreter will check for correct datatypes in |
| 47 | the following circumstances: |
| 48 | - arguments on function calls, |
| 49 | - return values of functions, |
| 50 | - assignment to variables, |
Zesstra | 5481d49 | 2021-04-08 20:07:06 +0200 | [diff] [blame] | 51 | - declarative type casts, |
Zesstra | 7ea4a03 | 2019-11-26 20:11:40 +0100 | [diff] [blame] | 52 | - restoration of values to variables or struct members. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 53 | Don't confuse this with strong/strict_types, they only |
| 54 | check at compile time. |
| 55 | strong_types/strict_types is seriously recommended. |
| 56 | This pragma implicitly enables save_types as well. |
Zesstra | 7ea4a03 | 2019-11-26 20:11:40 +0100 | [diff] [blame] | 57 | warn_rtt_checks: runtime checks are enabled, just like rtt_checks, |
| 58 | but errors will be shown as warnings only. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 59 | no_rtt_checks: disable runtime type checks for this program (default). |
| 60 | |
| 61 | pedantic: Certain warnings are treated as errors: |
Zesstra | 7ea4a03 | 2019-11-26 20:11:40 +0100 | [diff] [blame] | 62 | - failure to pass enough arguments to simul efuns |
| 63 | - type casts with no effect |
| 64 | - inconsistent declarations |
| 65 | - inconsistent overloads |
| 66 | - double inherits |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 67 | sloppy: Turns off pedantic (the default). |
| 68 | |
| 69 | range_check: Use of questionable ranges (ranges of negative sizes, |
| 70 | or with bounds beyond the array's size) cause a runtime |
| 71 | warning. |
| 72 | no_range_check: Turns off range_check (the default). |
| 73 | |
| 74 | warn_deprecated: Use of deprecated efuns or indexing operations |
| 75 | causes the compiler to issue a warning (the default). |
| 76 | no_warn_deprecated: Turns off warn_deprecated. |
| 77 | |
| 78 | warn_empty_casts: A cast of a value to its own type generates |
Zesstra | 7ea4a03 | 2019-11-26 20:11:40 +0100 | [diff] [blame] | 79 | a warning. Also casting a value of mixed/unknown type or |
| 80 | casting to mixed will generate a warning (the default). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 81 | no_warn_empty_casts: Turns off warn_empty_casts. |
| 82 | |
| 83 | warn_missing_return: Warn if a value-returning function is missing |
| 84 | a return statement (the default). If possible, the driver |
| 85 | will try to detect this at compile time; otherwise a runtime |
| 86 | warning will be generated when the function is executed. |
| 87 | The check applies only to functions with a declared return |
| 88 | type other than 'void'. |
| 89 | no_warn_missing_return: Turn off warn_missing_return. |
| 90 | |
Zesstra | 98e90af | 2021-05-07 19:18:04 +0200 | [diff] [blame] | 91 | warn_dead_code: Warn about dead code. Code is considered dead if |
| 92 | it can never be executed. The driver has only limited |
| 93 | analysis capabilities and cannot detect all instances |
| 94 | of dead code. |
| 95 | no_warn_dead_code: Turn off warn_dead_code (the default). |
| 96 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 97 | warn_function_inconsistent: If an inherited function is |
| 98 | overloaded with inconsistent return types or arguments, |
| 99 | a warning is generated; or if pragma_pedantic is in effect, |
| 100 | an error. By default this is active. |
| 101 | no_warn_function_inconsistent: An inherited function can |
| 102 | be overloaded with inconsistent return types or arguments, |
| 103 | as long as pragma_pedantic is not in effect. |
| 104 | |
| 105 | This pragma is meant to easen the adaption of legacy |
| 106 | mudlib code - in general one should fix the warnings, |
| 107 | not turn them off. |
| 108 | |
Zesstra | 98e90af | 2021-05-07 19:18:04 +0200 | [diff] [blame] | 109 | warn_applied_functions: If a function is known to be an applied |
| 110 | lfun, warn if its declaration differs from the specification. |
| 111 | no_warn_applied_functions: Turn of warn_applied_functions |
| 112 | (the default). |
| 113 | |
Zesstra | 5481d49 | 2021-04-08 20:07:06 +0200 | [diff] [blame] | 114 | warn_unused_variables: Warn about variables that are not used. |
Zesstra | 3085c66 | 2025-08-02 18:31:10 +0200 | [diff] [blame] | 115 | It will warn about variables never written to, variables |
Zesstra | 5481d49 | 2021-04-08 20:07:06 +0200 | [diff] [blame] | 116 | never read from or variables never used at all. |
| 117 | This applies to local variables and private global variables. |
| 118 | no_warn_unused_variables: Turn off warn_unused_variables |
| 119 | (the default). |
| 120 | |
Zesstra | 3085c66 | 2025-08-02 18:31:10 +0200 | [diff] [blame] | 121 | warn_unused_values: Warn about values that are not used. |
| 122 | It will warn about values that are created without |
| 123 | side-effects (eg. a literal value or created by some |
| 124 | operation) and are not used afterwards. |
| 125 | no_warn_unused_values: Turn off warn_unused_values (the default). |
| 126 | |
Zesstra | 5481d49 | 2021-04-08 20:07:06 +0200 | [diff] [blame] | 127 | warn_lightweight: Warn about efuns that are not suitable for |
| 128 | lightweight objects. |
| 129 | no_warn_lightweight: Turn off warn_lightweight. |
| 130 | |
Zesstra | 3085c66 | 2025-08-02 18:31:10 +0200 | [diff] [blame] | 131 | save_local_names: When activated the name of local variables |
| 132 | are saved for debugging purposes. This increases the |
| 133 | size of the program. |
| 134 | no_save_local_names: Turn off save_local_names (the default). |
| 135 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 136 | When an object is compiled with type testing (#pragma |
| 137 | strict_types), all types are saved of the arguments for that |
| 138 | function during compilation. If the #pragma save_types is |
| 139 | specified, then the types are saved even after compilation, to |
| 140 | be used when the object is inherited. |
| 141 | |
| 142 | The following two pragmas are available if the driver was |
| 143 | compiled with DEBUG and TRACE_CODE options: |
| 144 | |
| 145 | set_code_window: Sets an offset to the current program writing |
| 146 | position. Use this BEFORE a piece of code where you |
| 147 | want to check to what bytecodes it is compiled. |
| 148 | show_code_window: shows some bytes starting at or near the |
| 149 | last point set_code_window was called. |
| 150 | |
| 151 | EXAMPLES |
| 152 | #pragma strict_types |
| 153 | #pragma no_clone, no_inherit |
| 154 | |
| 155 | HISTORY |
| 156 | LDMud 3.2.7 added local_scopes, no_local_scopes, no_clone |
| 157 | and no_inherit. |
| 158 | LDMud 3.2.8 added weak_types, pedantic and sloppy. |
| 159 | LDMud 3.2.9 allowed to specify multiple pragmas in one directive. |
| 160 | LDMud 3.2.9 added (no_)warn_deprecated. |
| 161 | LDMud 3.2.10 added (no_)warn_empty_casts. |
| 162 | Starting with LDMud 3.2.10, #pragma xxx_types in an included file are |
| 163 | no longer valid only until the end of the file, but remain active |
| 164 | when processing returns to the including file. |
| 165 | LDMud 3.2.11 added (no_)warn_function_inconsistent. |
| 166 | LDMud 3.3.378 added init_variables, share_variables. |
| 167 | LDMud 3.3.357 added (no_)warn_missing_return. |
| 168 | LDMud 3.3.646 added (no_)range_check. |
| 169 | LDMud 3.5.0 removed combine_strings and no_combine_strings. |
| 170 | LDMud 3.5.0 removed local_scopes and no_local_scopes. |
| 171 | LDMud 3.5.0 removed verbose_errors (making its behaviour mandatory). |
| 172 | LDMud 3.5.0 enabled warn_deprecated by default. |
| 173 | |
| 174 | SEE ALSO |
| 175 | inheritance(LPC), initialisation(LPC), objects(C), |
| 176 | operators(LPC) |