/Study_CPP

2019

Primary LanguageAssembly

study_cpp

2019 new prj

Targets:

  1. Learn C++ from C, think in C++.
  2. Design Patterns?

Done:

  1. basic operator overloading
  2. reading "The C++ programming Language" by Bjarne Stroustrup
    1. Feeling

      I must say that I hate the way the author writes about C, like: "C is a subset of C++", "C++ is a better C" . really??? This standard book also has too much "pride" attitudes about C++ "invention", cannot compare to the simplicity-straight forwarded book written by Brian W.Kernighan & Dennis M.Ritchie. Anyway, now I have to deal with this book to "think in C++", it had better be as good as it is introduced.

    2. Intro
      1. classes oriented.
      2. type strict at compile time.
    3. Basics
      1. "auto" type.
      2. const (validate at runtime), constexpr (at compile time).
      3. variable can be defined on the fly. (but Stack space is reserved at the beginning, doesn't it??).
      4. the null pointer: "nullptr" (all zero 0) is used in C++, be careful in comparing C-functions which return "NULL (void*)0" or 0.
      5. "reference": no need to use "*" to access the value the reference refer to. Can only be referred at initialize.
        References are less powerful than pointers 1) Once a reference is created, it cannot be later made to reference another object; it cannot be reseated. This is often done with pointers. 2) References cannot be NULL. Pointers are often made NULL to indicate that they are not pointing to any valid thing. 3) A reference must be initialized when declared. There is no such restriction with pointers Due to the above limitations, references in C++ cannot be used for implementing data structures like Linked List, Tree, etc. In Java, references don’t have above restrictions, and can be used to implement all data structures. References being more powerful in Java, is the main reason Java doesn’t need pointers. References are safer and easier to use: 1) Safer: Since references must be initialized, wild references like wild pointers are unlikely to exist. It is still possible to have references that don’t refer to a valid location (See questions 5 and 6 in the below exercise ) 2) Easier to use: References don’t need dereferencing operator to access the value. They can be used like normal variables. ‘&’ operator is needed only at the time of declaration. Also, members of an object reference can be accessed with dot operator (‘.’), unlike pointers where arrow operator (->) is needed to access members.
        https://www.geeksforgeeks.org/pointers-vs-references-cpp/
      6. enumerations: enum class XYZ { A, B, C}; XYZ::A
      7. namespace mycode { int main() {}} mycode::main()
      8. Error handlings, pg.55
        1. throw exception_type{"log"}
        2. invariant, try catch(err)
        3. static_assert (on compile, to check const type)
        C++ runtime cannot catch Floating Point Exception, must do it manually :|
    4. Abstract, virtual x() = 0; (pure virtual)
      Class hierarchy offers:
      - interface inheritance
      - implementation inheritance
    5. Basic facilities
      6. Types, keywords, initialization
      - X a1{v}; // list initialization does not allow arrowing (char to int, not int to char, etc)
      - X a2 = {v}; X a3 = v; // C style; for auto var,
      - X a4(v); // constructor, not supported by all standard types (e.g std::string)
      - auto x;
      - dectltype
      //template auto operator+(const Matrix& a, const Matrix& b) −> Matrix - life time: auto, static, free store, temporary object, thread_local (TLS/TSpecifiedS)
              </li>
          </ol>
      </li>
      <li>Common Bug, Note</br>
          <ol>
              <li> RES  --  Resident Memory Size (KiB) is The non-swapped physical memory a task is using. </li>
              <li> WATCHDOG </li>
              <li> http://www.embeddedsystemonline.com/programming-languages/cplusplus/program-to-track-memory-allocations-in-c-or-c
                  </br>
                  new operator: </br>
                   https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/libsupc%2B%2B/new_op.cc?view=markup
              </li>
              <li>TODO generate web pages & rest services from C++ class</li>
          </ol>
      </li>