Compilation of Awkward Syntax

Discussion in 'C++' started by Joe Snodgrass, Apr 27, 2013.

  1. 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.
    Joe Snodgrass, Apr 27, 2013
    #1
    1. Advertising

  2. Joe Snodgrass

    Stefan Ram Guest

    Joe Snodgrass <> writes:
    >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.
    Stefan Ram, Apr 27, 2013
    #2
    1. Advertising

  3. Joe Snodgrass <> 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.
    Alain Ketterlin, Apr 27, 2013
    #3
  4. Joe Snodgrass

    Nobody Guest

    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>*.
    Nobody, Apr 27, 2013
    #4
  5. Joe Snodgrass

    osmium Guest

    "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.
    osmium, Apr 27, 2013
    #5
  6. Joe Snodgrass

    Tony Guest

    In article <>,
    says...
    >
    > I've almost finished teaching myself C++


    How long did it take you from start to finish?
    Tony, Apr 28, 2013
    #6
  7. On Apr 28, 5:55 am, Tony <> wrote:
    > In article <..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?
    Joe Snodgrass, May 1, 2013
    #7
  8. Joe Snodgrass

    Stefan Ram Guest

    Joe Snodgrass <> writes:
    >On Apr 28, 5:55 am, Tony <> wrote:
    >>In article <>,
    >> 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!
    Stefan Ram, May 1, 2013
    #8
  9. Joe Snodgrass

    Balog Pal Guest

    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.)
    Balog Pal, May 2, 2013
    #9
  10. Joe Snodgrass

    Tony Guest

    In article <>,
    says...
    >
    > On Apr 28, 5:55 am, Tony <> wrote:
    > > In article <>,
    > > 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).
    Tony, May 2, 2013
    #10
  11. Tony <> wrote:
    > In article <>,
    > says...
    >>
    >> On Apr 28, 5:55 am, Tony <> wrote:
    >>> In article <>,
    >>> 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).


    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
    Tobias Müller, May 2, 2013
    #11
  12. Joe Snodgrass

    Tony Guest

    In article <-
    september.org>, says...
    >
    > Tony <> wrote:
    > > In article <>,
    > > says...
    > >>
    > >> On Apr 28, 5:55 am, Tony <> wrote:
    > >>> In article <>,
    > >>> 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).

    >
    > 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.
    Tony, May 2, 2013
    #12
  13. Joe Snodgrass

    Bo Persson Guest

    Joe Snodgrass skrev 2013-05-01 23:54:
    > On Apr 28, 5:55 am, Tony <> wrote:
    >> In article <>,
    >> says...
    >>
    >>> I've almost finished teaching myself C++

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

    >
    > 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
    Bo Persson, May 2, 2013
    #13
  14. Joe Snodgrass

    Stefan Ram Guest

    Stefan Ram, May 2, 2013
    #14
  15. Joe Snodgrass

    James Kanze Guest

    On Thursday, 2 May 2013 04:41:43 UTC+1, Tony wrote:
    > In article <>,
    > says...
    > >
    > > On Apr 28, 5:55 am, Tony <> wrote:
    > > > In article <>,
    > > > 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).


    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.

    --
    James
    James Kanze, May 2, 2013
    #15
  16. Tonyæ–¼ 2013å¹´5月2日星期四UTC+8上åˆ11時41分43秒寫é“:
    > In article <>,
    >
    > says...
    >
    > >

    >
    > > On Apr 28, 5:55 am, Tony wrote:

    >
    > > > In article ,

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


    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.
    88888 Dihedral, May 2, 2013
    #16
  17. Joe Snodgrass

    Tony Guest

    In article <>,
    says...
    >
    > On Thursday, 2 May 2013 04:41:43 UTC+1, Tony wrote:
    > > In article <>,
    > > says...
    > > >
    > > > On Apr 28, 5:55 am, Tony <> wrote:
    > > > > In article <>,
    > > > > 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).

    >
    > 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.
    Tony, May 3, 2013
    #17
  18. Joe Snodgrass

    Tony Guest

    In article <>, says...
    >
    > Joe Snodgrass skrev 2013-05-01 23:54:
    > > On Apr 28, 5:55 am, Tony <> wrote:
    > >> In article <>,
    > >> says...
    > >>
    > >>> I've almost finished teaching myself C++
    > >>
    > >> How long did it take you from start to finish?

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


    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"?
    Tony, May 3, 2013
    #18
  19. Joe Snodgrass

    James Kanze Guest

    On Friday, 3 May 2013 05:04:38 UTC+1, Tony wrote:
    > In article <>,
    > says...


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

    --
    James
    James Kanze, May 3, 2013
    #19
  20. On May 1, 6:52 pm, -berlin.de (Stefan Ram) wrote:
    > JoeSnodgrass <> writes:
    > >On Apr 28, 5:55 am, Tony <> wrote:
    > >>In article <>,
    > >> 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!


    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!!
    Joe Snodgrass, May 4, 2013
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. beginner

    Awkward format string

    beginner, Aug 1, 2007, in forum: Python
    Replies:
    11
    Views:
    492
    beginner
    Aug 2, 2007
  2. C__chp
    Replies:
    4
    Views:
    502
    Puppet_Sock
    Feb 15, 2008
  3. Steven Woody
    Replies:
    3
    Views:
    358
    James Kanze
    Jul 11, 2008
  4. Ben Phillips
    Replies:
    6
    Views:
    868
    Roger Lindsjö
    Aug 23, 2008
  5. rickman

    Awkward Arithmetic

    rickman, Mar 15, 2010, in forum: VHDL
    Replies:
    9
    Views:
    589
    rickman
    Mar 22, 2010
Loading...

Share This Page