Sujet : Re: value-flavoured structures
De : no.email (at) *nospam* nospam.invalid (Paul Rubin)
Groupes : comp.lang.forthDate : 28. Sep 2024, 18:52:13
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87plond5te.fsf@nightsong.com>
References : 1 2 3 4 5
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
albert@spenarnc.xs4all.nl writes:
A strong type system is not a problem for embedded applications, as long
as there is a means to defeat the type system.
Ada was designed with this in mind, making distinction between safe and
unsafe modules. Remember that c++ was an afterthought after c that was
not well designed in the first place.
Rust has unsafe modules but I don't remember Ada having them. Ada does
have an Unchecked_Conversion function but I don't know where this is
really needed or how well specified it is in the language standard.
Usually in Ada, for low level operations involving things like machine
registers, you'd call subroutines written in assembly language or
similar. Even in C you sometimes have to do that: any operating system
written in C will contain some asm code.
Strong typing can be annoying. I remember wasting time passing a filename
to function that expected a `const char *` or something, and it is
By filename do you mean a char*, or a counted string (std::string), or
something? There shouldn't be a problem passing a char* to a function
expecting const char*, since the function simply promises to not modify
the string. The error is the other direction, passing a const char*
to something that takes a char*, i.e. that doesn't make such a promise.
For std::string there is a builtin that converts to a char* (null
terminated string).
by no means obvious what you have to do, so you are lured into casting.
A lot of people do not understand that casting is a means to defeat the
type system, so that you loose the advantages.
Yes exactly, casting in C++ is a code smell. I'm not a C++ expert and
haven't written a ton of C++ code, but in what I've written, I don't
remember having needed to cast.