Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is this valid C++-code?

27 views
Skip to first unread message

Bonita Montero

unread,
Sep 13, 2019, 9:10:17 AM9/13/19
to
I have some tempalted code that loads a variable of a template-type with
"xxx = T( -1 )". This is of course ok if T is a class with a constructor
which accepts an appropriate type. But I checked this if T is a pointer
and found that this also works. So this here is non-templated sample
code of which I'd like to know if this is valid C++:

typedef int *PI;
PI pi;
void f()
{
::pi = PI( -1 );
}

But at least this compiles with VC++, gcc and clang.

David Brown

unread,
Sep 13, 2019, 9:35:16 AM9/13/19
to
It is a "functional cast expression". "PI(-1)" is identical in
functionality to "(PI) -1".

And like the C-style cast, it has implementation-dependent behaviour.

Bonita Montero

unread,
Sep 13, 2019, 9:47:57 AM9/13/19
to
>> But at least this compiles with VC++, gcc and clang.

> It is a "functional cast expression". "PI(-1)" is identical in
> functionality to "(PI) -1".
> And like the C-style cast, it has implementation-dependent behaviour.

Sorry, I had tomatoes on my eyes when I posted thi.
The above came into my mind shortly after I posted this.

David Brown

unread,
Sep 14, 2019, 7:36:38 AM9/14/19
to
On 13/09/2019 15:47, Bonita Montero wrote:
>>> But at least this compiles with VC++, gcc and clang.
>
>> It is a "functional cast expression".  "PI(-1)" is identical in
>> functionality to "(PI) -1".
>> And like the C-style cast, it has implementation-dependent behaviour.
>
> Sorry, I had tomatoes on my eyes when I posted thi.

That is a nice way to put it. Is that a direct translation of an idiom
in your native tongue?

> The above came into my mind shortly after I posted this.
>

We all do that sometimes.

Bonita Montero

unread,
Sep 14, 2019, 1:05:55 PM9/14/19
to
>> Sorry, I had tomatoes on my eyes when I posted thi.

> That is a nice way to put it.
> Is that a direct translation of an idiom in your native tongue?

Yes, that's a saying in my language for something you haven't
seen but what should be seen obviously. I already thought that
this isn't directly translatable, but I also thought the meaning
could be guessed easily.
0 new messages