Matlab
function arguments validation
syntax is generally recommended over the legacy validateattributes() and inputParser() techniques.
Function arguments validation specification coerces the input and/or output variables to the class declaration given if possible, and errors otherwise.
Default values are easily specified, which required such verbose syntax before.
only a single class can be specified
recall the .empty method of most Matlab classes e.g. datetime.empty() that allows initializing an empty array.
Matlab argument validation syntax coerces class at runtime.
An example of Matlab function argument validate on input and output arguments is in
matlab-stdlib.
Several modern, currently-supported compiler families are free-to-use for C, C++ and Fortran.
GCC has broad support of modern standards on a very wide range of computing platforms.
GCC’s downside in some cases can be slower runtime performance than compilers having less broad language and platform support.
Git uses the EDITOR environment variable to determine which text editor to use for commit messages.
Since the commit message editing is typically small and simple, it may be desired to set a distinct text editor just for Git.
This is done via Git global config:
Most environment variable have alphanumeric names and don’t need any special consideration to access.
On Windows, some important programs still use the “Program Files (x86)” directory, denoted by environment variable “ProgramFiles(x86)”.
programenvimplicitnoneinteger::icharacter(100)::pathcallget_environment_variable('ProgramFiles(x86)',path,status=i)if(i/=0)error stop"env var ProgramFiles(x86) not found"print'(a)',pathendprogramenv
If rotating tick labels, the overall axes typically need to be positioned to allow for the rotated labels, otherwise the tick labels can be cut off the figure edges.
The axes position is updated automatically with
constrained_layout
option of figure().
If a DLL conflicts with a programs needed DLLs, the program may quit with a specific message, or it may silently exit.
The
return code
may correspond to segfault or other error.
To help see if a DLL conflict is occurring, use
gdb
to run the program.
This works even for general programs that weren’t built on the system.
We suggest obtaining GDB via
MSYS2.
If there is a problem with a DLL, GDB will often print the name of the DLL.
If the DLL is in an unexpected location, this may indicate a directory that should not be in environment variable Path.
On macOS when using the default “AppleClang” compiler in a Fortran project where GFortran objects are linked with C/C++ objects, the ld linker may emit warnings like:
ld: warning: could not create compact unwind for ...: register .. saved somewhere other than in frame
ld: warning: could not create compact unwind for ...: registers .. and .. not saved contiguously in frame
This is an actual issue because C++ exception handling will not completely work when this warning is emitted from C++ code coupled with Fortran code.
In general, using C++ exception handling within C++ code that is linked with Fortran code will work just fine, except when this warning is issued.
The solution is to use GNU GCC C++ compiler with GFortran instead of mixing AppleClang with GFortran.
Specifying environment variable:
LDFLAGS="-Wl,-no_compact_unwind"
removes the warning, but this also disables C++ exception handling so is not recommended.
It is possible to programmatically detect this link conflict from CMake using
try_compile.
try_compile(abi_compilePROJECTabi_checkSOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/abi_checkOUTPUT_VARIABLEabi_output)if(abi_outputMATCHES"ld: warning: could not create compact unwind for")message(WARNING"C++ exception handling will not work reliably due to incompatible compilers:
C++ compiler ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}
Fortran compiler ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION}" )endif()
CMake has built-in support for C/C++ static code analysis tools such as
CppCheck.
Apply CppCheck to CMake targets with
CMakeLists.txt
by setting
CMAKE_CXX_CPPCHECK.
File “cppcheck.supp” contains suppressions for false positives.
NOTE: CMake runs cppcheck from an arbitrary directory, so per-file suppressions in the file don’t work as usual.
To suppress a warning for a specific file, use the --suppress option to cppcheck in CMakeLists.txt like:
When moving between Linux systems that often default to Bash, and macOS systems that often default to
Zsh,
one may wish to change the default shell parameters.
For example, to remove duplicate entries in shell history, so that pressing “up” on repeated commands doesn’t make you press “up” repeatedly to get to the last non-duplicated command, set like the following.
Bash: ~/.inputrc: ignore duplicate lines, and omits lines that start with space.
exportHISTCONTROL=ignoreboth
Zsh: ~/.zshrc: approximately the equivalent of the above Bash setting.