From: Gene on
On Apr 15, 4:59 am, "J-P. Rosen" <ro...(a)adalog.fr> wrote:
> While preparing the upcomming "Using Object Oriented Technologies in
> Secure Systems" tutorial for Ada-Europe (plug, plug...), I came across
> this beautiful statement (OOTiA, B.1.1.6):
>
> "C++ is a strongly typed language, if conversions between logically
> unrelated types are avoided".
>
> Ain't that cute?

Too, motorcycles are perfectly safe until you have an accident.
From: J-P. Rosen on
Maciej Sobczak a �crit :
[..]
> No. Not only it is not logical - it will not even compile.
>
[...]
> Your example above cannot compile, because the actual parameter int
> cannot be promoted to long (int is never promoted, only "lower" types
> are) and its conversion to either short or long has equal rank -
> therefore the call is ambiguous.
>
> This has *nothing* to do with representation - these types are all
> different even if they have the same representation.
>
[...]
> Overload resolution does *not* depend on implementation in C++, it is
> precisely defined with no relation to representation.
I admit my C++ is a bit old, based mainly on Stroustrup where I picked
this example from. Is current C++ differs, it is a good thing, but I
still wonder
1) if your description is about standard (1998) C++?
2) if all compilers really behave like this?

> Just imagine - what would happen if there was a C++ programmer on your
> tutorial and you presented these arguments? ;-) ;-) ;-)
If my point is wrong, I'll withdraw it. The first thing when arguing is
to have valid argument, otherwise it is too easy to dismiss you.
Thanks for pointing out valid arguments!

--
---------------------------------------------------------
J-P. Rosen (rosen(a)adalog.fr)
Visit Adalog's web site at http://www.adalog.fr
From: Maciej Sobczak on
On 18 Kwi, 10:04, "J-P. Rosen" <ro...(a)adalog.fr> wrote:

> I admit my C++ is a bit old, based mainly on Stroustrup where I picked
> this example from. Is current C++ differs, it is a good thing, but I
> still wonder
> 1) if your description is about standard (1998) C++?

This is where I looked at. If necessary/helpful I can provide relevant
citations and paragraph numbers.

> 2) if all compilers really behave like this?

I still don't have a fully-compliant Ada 2005 compiler, so...

Back to C++ - it does not matter what *all* compilers do; what does
matter in the industry is what the two most popular do (g++/VC++).
There are plenty of "C++" compilers around.

> Thanks for pointing out valid arguments!

There is no reason to hide them - awareness of problems benefits
everybody.

--
Maciej Sobczak * http://www.inspirel.com

YAMI4 - Messaging Solution for Distributed Systems
http://www.inspirel.com/yami4
From: Maciej Sobczak on
On 18 Kwi, 22:38, Gautier write-only <gautier_niou...(a)hotmail.com>
wrote:

> - in C++, is it possible to do arithmetic with the (or a) boolean
> type, or convert silently from/to integer ?

Yes, bool is promoted to int (false->0, true->1) when used in mixed
context.

> - in C++, is it possible to assign a value of a type enum1 to a
> variable of type enum2,

No. Enums are distinct types and assignment between them requires
explicit conversion.

> or is it possible to do any mix or arithmetic
> without something like enum1'Pos ?

Enums can be promoted to int, so you can do "arithmetic" on them.
But you would not be able to silently assign the result back to enum,
as conversion from int (the result of "arithmetic") would have to be
explicit.

That is, you cannot use these tricks to silently subvert the type
system to mess the value of the enumeration type.

--
Maciej Sobczak * http://www.inspirel.com

YAMI4 - Messaging Solution for Distributed Systems
http://www.inspirel.com/yami4