Forum > Embedded

light pascal

<< < (12/12)

ccrause:
Whether a feature is available or not is not known by the compiler, since the feature support is included (or not) depending on the features enabled when the RTL was compiled.  The RTL supported features are available as compile time macros.  To see this add command line option -va when compiling a unit or program.  The compiler will then list the available features for the current subarch RTL.  Below I have copied the feature macros displayed after the compiler loaded the system unit when compiling one of my AVR projects:


--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Debug: [0.051] (SYSTEM)   (10056) Finished loading unit SYSTEMDebug: [0.051] Searching file adctest.pp... foundDebug: [0.051] Searching file adctest.pp... foundDebug: [0.051] /home/christo/fpc/fpc-avr/src/examples/adc4809/adctest.pp(3,5)  (3101) Macro defined: FPC_HAS_FEATURE_HEAPDebug: [0.051] /home/christo/fpc/fpc-avr/src/examples/adc4809/adctest.pp(3,5)  (3101) Macro defined: FPC_HAS_FEATURE_RTTIDebug: [0.051] /home/christo/fpc/fpc-avr/src/examples/adc4809/adctest.pp(3,5)  (3101) Macro defined: FPC_HAS_FEATURE_TEXTIODebug: [0.051] /home/christo/fpc/fpc-avr/src/examples/adc4809/adctest.pp(3,5)  (3101) Macro defined: FPC_HAS_FEATURE_FILEIODebug: [0.051] /home/christo/fpc/fpc-avr/src/examples/adc4809/adctest.pp(3,5)  (3101) Macro defined: FPC_HAS_FEATURE_OBJECTSDebug: [0.051] (ADCTEST)  (10057) Registering new unit OBJPAS
This way you can test whether a feature is supported before trying to use it in code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  {$if defined(FPC_HAS_FEATURE_CLASSES)}  TTest = class    procedure foo;  end;  {$elseif defined(FPC_HAS_FEATURE_OBJECTS)}  TTest = object    procedure foo;  end;  {$else}    {$fatal 'Either CLASSES or OBJECTS must be supported for this to compile'}  {$endif}

julkas:
Thanks. -va option is very useful.

Navigation

[0] Message Index

[*] Previous page

Go to full version