Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Compilation of Awkward Syntax

Reply
Thread Tools

Compilation of Awkward Syntax

 
 
Joe Snodgrass
Guest
Posts: n/a
 
      04-27-2013
I've almost finished teaching myself C++, but there's one last step I
have to take. I need to teach myself all the situations that require
one to use a strange looking combination of operators.

One example of a strange looking combination of operators that I
managed to work through is

tmp=(Node<int>*)ptr,

You can see that the >* is nothing like anything that would have been
seen in any previous (or structured) language.

I seem to recall seeing this sort of awkward syntax in several
different situations, when I read 2nd edition of Stroustrup, not just
this situation.

Does anybody know if someone has assembled a cheat sheet to pull them
all together in one place? TIA.
 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      04-27-2013
Joe Snodgrass <(E-Mail Removed)> writes:
>operators
>a cheat sheet


http://en.cppreference.com/w/cpp/lan...tor_precedence

Take into account that not all non-letter-non-digit-tokens
are operators, there also are punctuators and
non-letter-non-digit-tokens that are a part of some
lexical or syntactical unit.

>tmp=(Node<int>*)ptr,


To understand this you need to know the syntax of C++ and
also the context (where in a compilation unit it does appear).

>I've almost finished teaching myself C++,


To learn C++ yourself, some recommendable books are (in this
order and doing the exercises): As a start: Programming --
Principles and Practice Using C++ (only if you have not
programmed before) or Accelerated C++ (if you have
programmed before); later: The C++ Programming Language,
Effective C++, Exceptional C++ (Parts 1 and 2), Modern C++
programming, ISO/IEC 14882.

 
Reply With Quote
 
 
 
 
Alain Ketterlin
Guest
Posts: n/a
 
      04-27-2013
Joe Snodgrass <(E-Mail Removed)> writes:

> I've almost finished teaching myself C++, but there's one last step I
> have to take. I need to teach myself all the situations that require
> one to use a strange looking combination of operators.
>
> One example of a strange looking combination of operators that I
> managed to work through is
>
> tmp=(Node<int>*)ptr,


What exactly is strange here? It's just a type-cast.

> You can see that the >* is nothing like anything that would have been
> seen in any previous (or structured) language.


"i>*p" is perfectly correct C/C++ (provided p is a pointer to anything
that can be compared to i).

I'm not sure what you are looking for, but in any case ">*" in your
example is certainly not a "combination of operators" (whatever that
means), because that is not how this piece of text is parsed
(tokenized).

> I seem to recall seeing this sort of awkward syntax in several
> different situations, when I read 2nd edition of Stroustrup, not just
> this situation.
>
> Does anybody know if someone has assembled a cheat sheet to pull them
> all together in one place? TIA.


I must have missed something...

-- Alain.
 
Reply With Quote
 
Nobody
Guest
Posts: n/a
 
      04-27-2013
On Sat, 27 Apr 2013 05:58:11 -0700, Joe Snodgrass wrote:

> One example of a strange looking combination of operators that I
> managed to work through is
>
> tmp=(Node<int>*)ptr,


"Node<int>" is a type, a specialisation of the Node template with int
as the parameter. Template syntax uses < and > as brackets.

"Node<int>*" is also a type, a pointer to Node<int>.

"(Node<int>*)ptr" is a cast of ptr to the type Node<int>*.


 
Reply With Quote
 
osmium
Guest
Posts: n/a
 
      04-27-2013
"Nobody" wrote:

> On Sat, 27 Apr 2013 05:58:11 -0700, Joe Snodgrass wrote:
>
>> One example of a strange looking combination of operators that I
>> managed to work through is
>>
>> tmp=(Node<int>*)ptr,

>
> "Node<int>" is a type, a specialisation of the Node template with int
> as the parameter. Template syntax uses < and > as brackets.
>
> "Node<int>*" is also a type, a pointer to Node<int>.
>
> "(Node<int>*)ptr" is a cast of ptr to the type Node<int>*.


Perhaps what the OP could use is a C++ variant of "cdecl"; If there is none
it might be an interesting problem for someone looking for something to test
himself with.


 
Reply With Quote
 
Tony
Guest
Posts: n/a
 
      04-28-2013
In article <(E-Mail Removed)>,
http://www.velocityreviews.com/forums/(E-Mail Removed) says...
>
> I've almost finished teaching myself C++


How long did it take you from start to finish?

 
Reply With Quote
 
Joe Snodgrass
Guest
Posts: n/a
 
      05-01-2013
On Apr 28, 5:55*am, Tony <(E-Mail Removed)> wrote:
> In article <(E-Mail Removed)..com>,
> (E-Mail Removed) says...
>
> > I've almost finished teaching myself C++

>
> How long did it take you from start to finish?


Three months. Why do you ask?
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      05-01-2013
Joe Snodgrass <(E-Mail Removed)> writes:
>On Apr 28, 5:55*am, Tony <(E-Mail Removed)> wrote:
>>In article <(E-Mail Removed)>,
>>(E-Mail Removed) says...
>>>I've almost finished teaching myself C++

>> How long did it take you from start to finish?

>Three months. Why do you ask?


He might suspect that it might be a case of »It took 90 % of
the time to learn to first 90 % and it will take 90 % of the
time to learn the next 9 %.« (The other 90 % then will be
needed for the next 0.9 %.)

Can you explain:

- argument-dependent lookup
- SFINAE
- RAII
- RVO
- COW
- the rule of the three (today, also: five/zero)
- how to do exception-safe programming
- when should an operator be defined as a member?
- what is a scope guard?
- what is a good example of when to use a variadic
template?
- What is the copy-and-swap idiom
- When to use "const", when "constexpr"?
- Does C++ have 2 dimensional arrays?
- When to use "auto" vs when to use a specific type?
- the difference between operator new and the new
operator?
- the difference between member constants and constant
members?
- how to implement the factorial using template
metaprogramming
- type traits
- what algorithms are provided in the standard
library (header <algorithm>)
- CRTP - Curiously Recurring Template Pattern
- What smart pointers are provided by the standard
library, and when to use them?
- Functors
- policy-based design
- reinterpret_cast, dynamic_cast
- is the expression "a=2" an lvalue or an rvalue?
- move semantics
- perfect forwarding
- RTTI
- type erasure
- when to use "typename"
- What is »C++'s most vexing parse«?
- What is the difference between »int a=2;«,
»int a(2);« and »int a{2};«?

And this is just what immediately popped into my head,
but there is still much more to learn!

 
Reply With Quote
 
Balog Pal
Guest
Posts: n/a
 
      05-02-2013
On 5/2/2013 12:52 AM, Stefan Ram wrote:
> Can you explain:
>
> - argument-dependent lookup
> - SFINAE
> - RAII
> - RVO
> - COW
> - the rule of the three (today, also: five/zero)
> - how to do exception-safe programming
> - when should an operator be defined as a member?
> - what is a scope guard?
> - what is a good example of when to use a variadic
> template?
> - What is the copy-and-swap idiom
> - When to use "const", when "constexpr"?
> - Does C++ have 2 dimensional arrays?
> - When to use "auto" vs when to use a specific type?
> - the difference between operator new and the new
> operator?
> - the difference between member constants and constant
> members?
> - how to implement the factorial using template
> metaprogramming
> - type traits
> - what algorithms are provided in the standard
> library (header <algorithm>)
> - CRTP - Curiously Recurring Template Pattern
> - What smart pointers are provided by the standard
> library, and when to use them?
> - Functors
> - policy-based design
> - reinterpret_cast, dynamic_cast
> - is the expression "a=2" an lvalue or an rvalue?
> - move semantics
> - perfect forwarding
> - RTTI
> - type erasure
> - when to use "typename"
> - What is »C++'s most vexing parse«?
> - What is the difference between »int a=2;«,
> »int a(2);« and »int a{2};«?
>
> And this is just what immediately popped into my head,
> but there is still much more to learn!


Great list. When someone comes ahead as "I know C++" or claim to be
expert, my first reaction is "wow, then please explain me the two phase
lookup please". An if still around, to tell me the rules to select the
overload for foo(a, b) if we have certain types for a and b (including
variants with cv qualificaitons and refs and possible inplicit
conversions to other types), while foo is an overload set having
functions, templates, specialisations sitting in various namespaces.

(btw what I consider the full-score answer for the latter is "if you
have a proper overload set, then you should not care what is picked as
long as it compiles, and if the answer actually matters you are already
in trouble.)






 
Reply With Quote
 
Tony
Guest
Posts: n/a
 
      05-02-2013
In article <(E-Mail Removed)>,
(E-Mail Removed) says...
>
> On Apr 28, 5:55Â*am, Tony <(E-Mail Removed)> wrote:
> > In article <(E-Mail Removed)>,
> > (E-Mail Removed) says...
> >
> > > I've almost finished teaching myself C++

> >
> > How long did it take you from start to finish?

>
> Three months. Why do you ask?


Because becoming a master of C++ takes years and I'm wondering what the actual
number is on average. You said you were "almost done" learning C++. (I missed
the 'almost' when I posted, but the question is still valid).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Most awkward quote perhaps? philo Computer Support 2 03-22-2008 04:15 AM
Awkward format string beginner Python 11 08-02-2007 02:55 PM
Hardware Motherboard Awkward Problem at Startup - VIA K7VM2 QUIROGACA Computer Support 2 11-14-2006 06:49 AM
A little awkward Anonyma Computer Support 9 06-27-2006 06:33 AM
The Kanye West show was Mike Myers SECOND awkward live tv moment heinzmenses@hotmail.com Digital Photography 31 09-12-2005 08:54 PM



Advertisments