Compilation of Awkward Syntax

J

Joe Snodgrass

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.
 
S

Stefan Ram

Joe Snodgrass said:
operators
a cheat sheet

http://en.cppreference.com/w/cpp/language/operator_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.
 
A

Alain Ketterlin

Joe Snodgrass said:
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.
 
N

Nobody

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>*.
 
O

osmium

Nobody said:
"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.
 
S

Stefan Ram

Joe Snodgrass said:
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!
 
B

Balog Pal

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.)
 
T

Tony

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).
 
T

Tobias Müller

Tony said:
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).

At some point you have to stop learning (in the sense of guided learning,
reading books and solving toy exercises) and start gaining experience with
real programs.

Of course you will still have to consult a book every now and then. If you
have a mentor who can help you, even better.

But you won't become a master if you never start using the language.

Tobi
 
T

Tony

At some point you have to stop learning (in the sense of guided learning,
reading books and solving toy exercises) and start gaining experience with
real programs.

Of course you will still have to consult a book every now and then. If you
have a mentor who can help you, even better.

But you won't become a master if you never start using the language.

Tobi

I started in the early 1990's. As I tend to avoid some of the language (I subset
it), I probably wouldn't score well on a test of the more esoteric "features",
and certainly being employed as a C++ programmer (again) is definitely not
something I would entertain.
 
B

Bo Persson

Joe Snodgrass skrev 2013-05-01 23:54:
Three months. Why do you ask?

Twenty years, so far. I'll tell you when I'm done.


The fun part is that when asked the classic question

"On a scale from 1-10, where Bjarne Stroustrup is a 10, how well do you
know C++?",

the answer is often 9 after 3 months, 8 after a year, and 7 after 5
years. I'm now probably down to 5 or 6.

And I guess Bjarne isn't at 10 either. :)


Bo Persson
 
J

James Kanze

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).

For what definition of master? What do you want to do with C++?
I'd say that with proper mentoring, an average person can learn
it sufficiently for most jobs in about six months. A gifted
person can learn it well enough to write a compiler for it in
about a year.

Of course, since it's not a dead language, you always have to
keep abreast. The C++ we write today isn't the C++ I learned 20
years ago.
 
8

88888 Dihedral

Tonyæ–¼ 2013å¹´5月2日星期四UTC+8上åˆ11時41分43秒寫é“:
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).

In C++ the object part, the name space of using objects or
functions from some other library, and the template part
are all static linked in the compile time except those
objects use virtual methods inside a loop.

I'll assume that you are not using an interpreter embedded with
your C++ programs.

Also the vector part does boundary checking all the time
just like the old Fortran way but not the notorious
C-assembly way.
 
T

Tony

For what definition of master? What do you want to do with C++?
I'd say that with proper mentoring, an average person can learn
it sufficiently for most jobs in about six months.

By any definition of "master". What you wrote above seems to fit right in with
your "all the expressivity of C++" BS, in that, now you're trying to make it
seem like C++ is easy to master? Pfft. I'd say, that you cannot have a real C++
programmer with less than 5 years from the start of using it. Secondly, I
theorize that USE TIME is not as important as THINK TIME, especially in the
initial years. It's just that complex, intricate, subtle, etc. How do I know?
I've been there, done that. Blind-usage/trained-monkey-usage of it is to fall
prey to the spiel. You end up with a highly-proficient-C++-programmer, that
can't program himself out of a paper bag without millions of lines of esoteric
C++. Now, if that programmer was actually a good one, he would step out of the
fog of C++ and realize that a simple and elegant solution could be had save for
C++ not being able to render along those constraints.

So somewhere during journeyman path, the programmer on the "C++ master"
direction begins building all kinds of libraries (the preprocessor not
withstanding) until a light bulb moment arrives and that programmer realizes
that it's futile endeavor.

Of course the "programmer" in my text above is actually a frustrated (with C++)
SOFTWARE DEVELOPER. Big difference. A "programmer" is one of those who code
under the direction of "a C++ master", the "master" part here taking on a whole
new context. They buy into the spiel like young men enlisting in the army "for
real good reason".

Am I digressing again? Anyway, you get my drift.

A gifted
person can learn it well enough to write a compiler for it in
about a year.

And what "gift" would that person possess, pray tell.
Of course, since it's not a dead language, you always have to
keep abreast. The C++ we write today isn't the C++ I learned 20
years ago.

Nor is it the one I abandoned years ago, and it's not like building more
scaffolding has made it any better OVERALL than it was back then. An appropriate
metaphor may be that it has a lot of momentum, but two tons of moving garbage
has more momentum than one ton of it, so more is not better.
 
T

Tony

Joe Snodgrass skrev 2013-05-01 23:54:

Twenty years, so far. I'll tell you when I'm done.


The fun part is that when asked the classic question

"On a scale from 1-10, where Bjarne Stroustrup is a 10, how well do you
know C++?",

the answer is often 9 after 3 months, 8 after a year, and 7 after 5
years. I'm now probably down to 5 or 6.

And I guess Bjarne isn't at 10 either. :)

I like that. (I know, everyone is saying, "duh, we know YOU would!"). I've been
down that road, reached 0 and wrapped around to 255 (at least no one can call me
a 2-bit (unsigned) int!). :)

Quiz for the day: What is an "int wit"?
 
J

James Kanze

Pfft. I'd say, that you cannot have a real C++
programmer with less than 5 years from the start of using it.

Then you're wrong, because I regularly see competent programmers
learn it in about six months. Not well enough to write
a compiler for it, but well enough to be efficiently productive
in our application code.
 
J

Joe Snodgrass

  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!

Any time you feel like showing off your exemplary knowledge by posting
extensive lists like that one, you just go right ahead. You're doing
me a big fat juicy favor by itemizing the advanced topics I'm now
ready to study. Please make the list as exhaustive as you possibly
can, so I can begin ticking items off it, starting the moment you post
it. The harder you can make it, the better, because I LIVE FOR THE
CHALLENGE!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top