Coding Tidbit

Software articles that can be consumed quickly

  • Home
  • About
  • Facebook
  • LinkedIn
  • Twitter
  • Instagram
  • April 5, 2021

    Anti-Pattern: Enum as Array Index with No Bound Check

    Recently, I encountered program crashes because of unscoped enum as array index pattern once in the workplace and another in an open source library where I added another item in the enum. Evidently, this anti-pattern is very popular among C++ developers. Open source code using Enum as Array Index pattern without bound check in its…

  • April 5, 2021

    Put sleep() to make more money from HFT. And Lock-free vs Block-free

    “Isn’t April Fools over?” the very first thought running through your mind after glancing at the title. Rest assured, this is not a trolling post to make a fool out of you. This year’s April Fool post is here, in case you missed the once-in-a-lifetime C++ joke of its kind. This article is about slowing…

  • April 1, 2021

    C++23: -> and :: to be replaced by . operator

    In the biggest change to C++ syntax, -> and :: operators are to be replaced by . operator in the upcoming C++23 AF00L proposal. The rationale behind this proposal is there can be no confusion (as to which operator to use). The :: operator is not only used in scope resolution and also as class-to-static_member.…

  • October 21, 2020

    CreateCertificateContext Failed

    CertCreateCertificateContext failure can be fixed with first exporting the certificate to DER Encoded Binary X.509 (cer file) manually. std::vector<BYTE> vec; PCCERT_CONTEXT pCertContext = NULL; if (pCertContext = ::CertCreateCertificateContext( PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, vec.data(), vec.size())) { std::cout << “Success!\n”; } else { std::cout << “Failure!\n”; } If one want to forgo the manual export option, CryptQueryObject can…

  • October 13, 2020

    Comment Toggle Trick

    This is a neat comment toggle trick. When you have two path of mutually exclusive code of execution, do this to enable the first section. Remove the first back slash to comment out the first section and uncomment the second section.

  • October 13, 2020

    Avoid Default Clause in Switch Case for Enum

    Do not define a default clause for enum in switch statement! Say in future, if another fruit type is added to the enum, default clause shall cause the C++ compiler not to warn you that you have not handled the case for the new fruit. enum class Fruit { Apple, Orange }; Fruit fruit =…

  • October 13, 2020

    Private Inheritance

    In private inheritance, the base class public access members are still public access in the derived class. Therefore the derived class still can call the base class functions and access its public data. But the user who instantiates the derived class, cannot access the public member of the base class, hence private inheritance. Public inheritance…

  • October 13, 2020

    Digitally Signing Without Worrying About Cert Expiry

    If you want your executable’s signature to be still valid after certificate validity period, you have to digitally sign it with a timestamp from one of the timestamp websites with /tr switch before its expiry. In my case, I choose timestamp.digicert.com. This command is for Windows only. signtool.exe sign /tr http://timestamp.digicert.com /f Cert.pfx /p password…

  • October 13, 2020

    Avoid False Sharing With C++11 alignas Keyword

    When two threads are frequently accessing and updating the 2 different but independent variables on the same cacheline, cache thrashing occurs as a result because when the thread updates its variable, the thread on another CPU core has its cacheline invalidated and have to fetch from the main memory again even though it is not…

  • October 13, 2020

    WiX: Escape Square Blanket

    In WiX, property is referenced by enclosing its name in square blanket. For example, “[foobar]”. When a text (which we have no control over) is enclosed in blankets but is not a property, how do we escape it? This is not a WiX problem but a MSI method of deducing whether a value is a…

←Previous Page
1 2 3 4 5
Next Page→

Blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
 

Loading Comments...
 

    • Follow Following
      • Coding Tidbit
      • Already have a WordPress.com account? Log in now.
      • Coding Tidbit
      • Edit Site
      • Follow Following
      • Sign up
      • Log in
      • Report this content
      • View site in Reader
      • Manage subscriptions
      • Collapse this bar