[SystemSafety] C++ and Pointers

David Crocker dcrocker at eschertech.com
Wed Jun 5 21:04:43 CEST 2019


>> That is, "memory location" is the only strong data type in C++.
<<

Not at all. Enumerations are strong types (use "enum class" to avoid
default conversions to int), so are all user-defined classes unless you
include implicit conversion operators in them. The unwelcome implicit
narrowing conversions between numeric types are easily avoided by using
a static checking tool, or in some cases just by turning on compiler
warnings.

David Crocker, Escher Technologies Ltd.
http://www.eschertech.com
Tel. +44 (0)20 8144 3265 or +44 (0)7977 211486

On 05/06/2019 14:46, Peter Bernard Ladkin wrote:
> On 2019-06-05 15:39 , David Crocker wrote:
>> Yes, "int* iPtr1, iPtr2" is confusing. Very few C or C++ programmers would write that. 
> Intentionally. They could be making a mistake or having finger trouble.
>
>> However, int and int* are incompatible types, so the compiler would catch any attempt to use iPtr2 as a pointer. 
> That is, "memory location" is the only strong data type in C++.
>
> PBL
>
> Prof. Peter Bernard Ladkin, Bielefeld, Germany
> MoreInCommon
> Je suis Charlie
> Tel+msg +49 (0)521 880 7319  www.rvs-bi.de
>
>
>
>
>
>
> _______________________________________________
> The System Safety Mailing List
> systemsafety at TechFak.Uni-Bielefeld.DE
> Manage your subscription: https://lists.techfak.uni-bielefeld.de/mailman/listinfo/systemsafety
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.techfak.uni-bielefeld.de/mailman/private/systemsafety/attachments/20190605/346c4a50/attachment.html>


More information about the systemsafety mailing list