Obvious Things C Should Do
Walter Bright
newshound2 at digitalmars.com
Tue Jan 14 07:56:29 UTC 2025
On 1/13/2025 9:00 AM, Zz wrote:
> https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3423.pdf
With all the features listed below, they'd be better off using D:
TrapC is a C language extension that improves code safety
TrapC memory management is automatic, cannot memory leak, with pointers
lifetime managed not garbage collected"
TrapC pointers may look the same as in C/C++, but all pointers are diligently
compiler managed and memory safe
TrapC pointers have Run-Time Type Information (RTTI), with typeof(), nameof() and
other details accessible
TrapC reuses a few code safety features from C++, notably member functions,
constructors, destructors and ‘new’
TrapC adds 2 keywords unique to TrapC: ‘trap’ (error handling) and ‘alias’
(operator,
function and data overloading)
TrapC removes 2 keywords: ‘goto’ and ‘union’, as unsafe and having been widely
deprecated from use
TrapC uses castplates to make C containers typesafe, without the complexity of C++
templates
TrapC printf() and scanf() are typesafe, overloadable, and have JSON and
localization
support built in
TrapC has an integer-based ‘decimal’ fixed-point data type suitable for use in
financial
transactions
TrapC is one-way ABI compatible with C, such that TrapC functions may call any C
function as-is
Passing a raw C pointer safely to a TrapC function requires extra steps,
because TrapC
pointers have hidden RTTI
TrapC has API-compatible versions of C POSIX and C++ STL standard libraries,
to not
return raw pointers
TrapC doesn’t do more than C for thread safety to prevent race conditions, but
may in the
future
More information about the Digitalmars-d
mailing list