473,473 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

strange grammar about volatile and operator overload

Hello everyone,
The following code,

Expand|Select|Wrap|Line Numbers
  1. operator const Outer::Inner * volatile & ();
  2.  
1.

I think it means an operator &, which returns const Inner* type and
takes no arguments, right?

2.

Adding volatile to return value means?

(I previously only used volatile to qualify variable)
thanks in advance,
George
Jan 29 '08 #1
5 1917
George2 schrieb:
Hello everyone,
The following code,

Expand|Select|Wrap|Line Numbers
  1. operator const Outer::Inner * volatile & ();
  2.  

1.

I think it means an operator &, which returns const Inner* type and
takes no arguments, right?

2.

Adding volatile to return value means?

(I previously only used volatile to qualify variable)
thanks in advance,
George
volaitle disables optimization

Kind regards
Jan 29 '08 #2
On Tue, 29 Jan 2008 14:13:07 +0100, Hans Mull
<de*******@googlemail.comwrote in comp.lang.c++:
George2 schrieb:
Hello everyone,
The following code,

Expand|Select|Wrap|Line Numbers
  1.  operator const Outer::Inner * volatile & ();
  2.  
1.

I think it means an operator &, which returns const Inner* type and
takes no arguments, right?

2.

Adding volatile to return value means?

(I previously only used volatile to qualify variable)
thanks in advance,
George
volaitle disables optimization
What a silly, incomplete, and absolutely wrong statement!

Consider this code:

extern volatile unsigned int vui; // defined and initialized elsewhere

unsigned int silly_func()
{
return vui * 2;
}

Are you really claiming that the compiler is forbidden from making the
strength reduction optimization of replacing the multiply with a left
shift by 1?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jan 29 '08 #3
On 2008-01-30 08:50:26, James Kanze wrote:
what's important here isn't the semantics of volatile, but the fact that
T* volatile isn't the same type as T* volatile.)
Is this a typo? If not, could you please explain?
In sum, the implementation defined semantics of volatile are, in most
cases, totally useless for anything.
Does this mean that it is not necessary to declare variables that are
accessed (read and write) by different threads as volatile? (In addition to
the necessary locking, of course.)

Gerhard
Jan 30 '08 #4
On Jan 30, 10:00 am, Gerhard Fiedler <geli...@gmail.comwrote:
On 2008-01-30 08:50:26, James Kanze wrote:
what's important here isn't the semantics of volatile, but the fact that
T* volatile isn't the same type as T* volatile.)

Is this a typo? If not, could you please explain?
In sum, the implementation defined semantics of volatile are, in most
cases, totally useless for anything.

Does this mean that it is not necessary to declare variables that are
accessed (read and write) by different threads as volatile? (In addition to
the necessary locking, of course.)

Gerhard
I will extend the Gerhard's question to: "and what about pointer to
memory mapped addresses?"

Diego
Jan 30 '08 #5
On Jan 30, 1:00 pm, Gerhard Fiedler <geli...@gmail.comwrote:
On 2008-01-30 08:50:26, James Kanze wrote:
what's important here isn't the semantics of volatile, but the fact that
T* volatile isn't the same type as T* volatile.)
Is this a typo?
I think so:-). What I probably meant to say was that T*& isn't
the same as T* volatile&. (Note that T* volatile and T* are the
same types, at least when they're return values.)

[...]
In sum, the implementation defined semantics of volatile
are, in most cases, totally useless for anything.
Does this mean that it is not necessary to declare variables
that are accessed (read and write) by different threads as
volatile? (In addition to the necessary locking, of course.)
It depends on what the threading specifications (and the
compiler definition of volatile) say. Under Posix, if you
haven't locked, volatile isn't sufficient, and if you have, it
isn't necessary. Current Windows works about the same, I think,
although I find it very hard to find any real published
specifications.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jan 31 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
4
by: Prawit Chaivong | last post by:
Hi, gurus I've overloaded new operator. and I found that size is strange. It's more than sizeof(myClass) 4 bytes. Where does it come from. I don't know the other compilers do the same thing....
7
by: dam_fool_2003 | last post by:
#include<stdio.h> int main(void) { unsigned int a=20,b=50, c = sizeof b+a; printf("%d\n",c); return 0; } out put: 24
4
by: Harlan Messinger | last post by:
Since operator overloads into static functions in C#, there really doesn't need to be a connection between the types to which the operator is being applied and the type in which the overload is...
17
by: Chris | last post by:
To me, this seems rather redundant. The compiler requires that if you overload the == operator, you must also overload the != operator. All I do for the != operator is something like this: ...
9
by: Tony | last post by:
I have an operator== overload that compares two items and returns a new class as the result of the comparison (instead of the normal bool) I then get an ambiguous operater compile error when I...
1
by: Frederick Gotham | last post by:
The canonical way to write a copy-constructor is: MyClass::MyClass(MyClass const&); I've been wondering, however, if that should be: MyClass::MyClass(MyClass const volatile&); ? Just in...
5
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.