Cross-Platform Compatibility Mode
Cross-Platform Compatibility Mode (CPM) is a a special mode of the compiler than can be activated (per project or per individual file, via Compiler Directive) that makes the compiler more lenient towards platform differences and makes it easier to write sharable code.
In essence, in Cross-Platform Compatibility Mode the compiler will be less strict in enforcing "clean" code for the current platform, in exchange for allowing you to write code that will work, without or with fewer {$IF}
/#if
s, on all platforms. It will also emit additional errors and warnings for code patterns that are not suitable for cross-platform sharing.
More Leniency
The compiler will be lenient and allow the following, which normally would result in errors or warnings:
- Identifiers where the case of the first letter is mismatched (
.ToString
vs.toString()
). - Mismatched casing in namespaces (which are generally all lowercase in Java, and PascalCased for the other platforms).
Case mismatches would otherwise of course be errors in C#, Swift, Java and Go, and optionally emit a warning when the "Warn on Case Mismatch" option is turned on in Oxygene or Mercury.
Additional Warnings
In addition, the compiler will emit warnings when using any of the following features, which are not available on all platforms, because using them will make the code inherently not cross-platform.
- Use of BigInteger constants
- Use of function pointers
- Use of
selector
(Oxygene) or__selector
(C#) syntax - Use of the Auto-Release Pool syntax
- Use of the
unsafe
keyword and unsafe code - Use of the
raises
keyword in Oxygene (supported on Java only) - Use of the
Optional
attribute on interface members (supported on Cocoa only) - Use of
parallel
, andqueryable sequence
(supported on .NET only) - Use of the
interlocked*()
APIs (not supported on Java) - Direct calls to
init.alloc
instead of a constructor (supported on Cocoa only) - Use of function, method, procedure pointers, which differ between .NET/Java vs. Cocoa
These warnings will be emitted for any code compiled in Cross-Platform mode that is not surrounded by {$IF}
/#if
s for a specific platform.