Sujet : Re: Computer architects leaving Intel...
De : monnier (at) *nospam* iro.umontreal.ca (Stefan Monnier)
Groupes : comp.archDate : 30. Aug 2024, 19:34:23
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <jwv7cbxq2xb.fsf-monnier+comp.arch@gnu.org>
References : 1 2 3
User-Agent : Gnus/5.13 (Gnus v5.13)
If you want to write reliable code that can be distributed as source and
compiled by any conforming C/C++ compiler, you need to be very sure that you
avoid relying on behaviour that is not specified and documented. You need to
write correct code. That means if you want to copy some memory with
overlapping source and destination arrays, you use "memmove" - the function
for that purpose. You don't use "memcpy", since it is specified explicitly
as requiring non-overlapping arrays.
The difficulty here is that the tools provide very little help for that,
because all too often it's virtually impossible for the tools to
understand that this particular code can/will hit UB.
So it's all up to the programmer, who often doesn't know either.
Other than using CompCert, I don't know of any reliable way for
a programmer to make sure his C code does not suffer from UB.
Stefan