Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Compilation of Awkward Syntax (http://www.velocityreviews.com/forums/t960172-compilation-of-awkward-syntax.html)

Joe Snodgrass 04-27-2013 12:58 PM

Compilation of Awkward Syntax
 
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.

Stefan Ram 04-27-2013 01:16 PM

Re: Compilation of Awkward Syntax
 
Joe Snodgrass <vaughan.andursen@gmail.com> 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.


Alain Ketterlin 04-27-2013 01:23 PM

Re: Compilation of Awkward Syntax
 
Joe Snodgrass <vaughan.andursen@gmail.com> 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.

Nobody 04-27-2013 07:29 PM

Re: Compilation of Awkward Syntax
 
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>*.



osmium 04-27-2013 07:41 PM

Re: Compilation of Awkward Syntax
 
"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.



Tony 04-28-2013 09:55 AM

Re: Compilation of Awkward Syntax
 
In article <cac6d15b-70d9-46a1-abae-db017b5d3717@b20g2000yqo.googlegroups.com>,
vaughan.andursen@gmail.com says...
>
> I've almost finished teaching myself C++


How long did it take you from start to finish?


Joe Snodgrass 05-01-2013 09:54 PM

Re: Compilation of Awkward Syntax
 
On Apr 28, 5:55*am, Tony <a...@some.org> wrote:
> In article <cac6d15b-70d9-46a1-abae-db017b5d3...@b20g2000yqo.googlegroups..com>,
> vaughan.andur...@gmail.com says...
>
> > I've almost finished teaching myself C++

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


Three months. Why do you ask?

Stefan Ram 05-01-2013 10:52 PM

Re: Compilation of Awkward Syntax
 
Joe Snodgrass <vaughan.andursen@gmail.com> writes:
>On Apr 28, 5:55*am, Tony <a...@some.org> wrote:
>>In article <cac6d15b-70d9-46a1-abae-db017b5d3...@b20g2000yqo.googlegroups.com>,
>>vaughan.andur...@gmail.com 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!


Balog Pal 05-02-2013 12:46 AM

Re: Compilation of Awkward Syntax
 
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.)







Tony 05-02-2013 03:41 AM

Re: Compilation of Awkward Syntax
 
In article <8c80b870-c9cb-449a-8cac-fa1940f3b72a@g9g2000yqh.googlegroups.com>,
vaughan.andursen@gmail.com says...
>
> On Apr 28, 5:55Â*am, Tony <a...@some.org> wrote:
> > In article <cac6d15b-70d9-46a1-abae-db017b5d3...@b20g2000yqo.googlegroups.com>,
> > vaughan.andur...@gmail.com 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).


All times are GMT. The time now is 09:51 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.