[SystemSafety] C++ and Pointers

David Crocker dcrocker at eschertech.com
Wed Jun 5 15:39:03 CEST 2019


>>

However, "int* iPtr1, iPtr2" is not equivalent to "int *iPtr1; int *iPtr2"; but rather to "int
*iPtr1; int iPtr2".
<<

Yes, "int* iPtr1, iPtr2" is confusing. Very few C or C++ programmers would write that. However, int and int* are incompatible types, so the compiler would catch any attempt to use iPtr2 as a pointer. So it's an unfortunate choice of syntax, but not a serious problem.

In function argument lists that syntax is not allowed and you are forced to write "int* iPtr1, int* iPtr2".

Operator overloading is a separate issue. Like any powerful language feature, it is very useful in an appropriate context, but can also be abused.

Regards

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

On 05/06/2019 11:36, Peter Bernard Ladkin wrote:
> There is a chap called Alex, who did his degree at UC Davis and also taught some programming there.
> He has a readable WWW site introducing C++ ,  https://www.learncpp.com
>
> It has been a while; I just looked up a couple of things about pointers, in Section 6. Some of the
> things he says - he needs to say - sent shivers up my spine.
>
> He points out that keysymbols "*" and "&" are overloaded. Let's just consider "*". "Although the
> dereference operator looks just like the multiplication operator, you can distinguish them because
> the dereference operator is unary, whereas the multiplication operator is binary."
>
> But that of course is not the only overloading. He goes on to explain declarations, which also use
> keysymbol "*". "int* iPtr"; "int * iPtr"; and "int *iPtr" all have exactly the same meaning.
> However, "int* iPtr1, iPtr2" is not equivalent to "int *iPtr1; int *iPtr2"; but rather to "int
> *iPtr1; int iPtr2".
>
> You need a static analyser just to tell you what your program means!
>
> 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/82c9d20d/attachment-0001.html>


More information about the systemsafety mailing list