<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kevin Albertson</title>
    <description>The latest articles on DEV Community by Kevin Albertson (@kevinalbs).</description>
    <link>https://dev.to/kevinalbs</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F649688%2F8ec9075a-d7e5-41b7-9e50-f573686f5b97.jpeg</url>
      <title>DEV Community: Kevin Albertson</title>
      <link>https://dev.to/kevinalbs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kevinalbs"/>
    <language>en</language>
    <item>
      <title>Test Driven Learning</title>
      <dc:creator>Kevin Albertson</dc:creator>
      <pubDate>Tue, 14 Mar 2023 00:58:37 +0000</pubDate>
      <link>https://dev.to/kevinalbs/test-driven-learning-3e9d</link>
      <guid>https://dev.to/kevinalbs/test-driven-learning-3e9d</guid>
      <description>&lt;p&gt;Idea: learn a new code base by writing tests. Read all of the public API. Come up with questions and try to answer them by writing tests.&lt;/p&gt;

&lt;p&gt;I tried this idea with the &lt;a href="http://mongoc.org/libbson/current/index.html"&gt;libbson&lt;/a&gt;. I help maintain libbson. I was curious to see what (if anything) I would learn by surveying and testing the public API.&lt;/p&gt;

&lt;p&gt;This is a summary of the results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Discover API
&lt;/h2&gt;

&lt;p&gt;I learned about the existence of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;BCON_EXTRACT&lt;/code&gt; to extract values from a &lt;code&gt;bson_t&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bson_unichar_t&lt;/code&gt; and related API to represent a Unicode codepoint in a &lt;code&gt;uint32_t&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bson_writer_t&lt;/code&gt; to write a sequence of BSON documents to a buffer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Find Surprising Behavior
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;bson_copy_to (&amp;lt;stack allocated&amp;gt;, &amp;lt;heap allocated&amp;gt;)&lt;/code&gt; results in a leak. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;test_bson_copy_to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;bson_t&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;dst&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bson_new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// dst is heap allocated.&lt;/span&gt;
    &lt;span class="n"&gt;bson_t&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;BSON_INITIALIZER&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// src is stack allocated.&lt;/span&gt;
    &lt;span class="n"&gt;BCON_APPEND&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;BCON_INT32&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;bson_copy_to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dst&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// struct for `bson_t` is leaked!&lt;/span&gt;
    &lt;span class="n"&gt;ASSERT_BSON_EQUAL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dst&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;bson_destroy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;bson_destroy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dst&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;bson_validate&lt;/code&gt; double validates UTF-8 values. &lt;code&gt;bson_iter_visit_all&lt;/code&gt; validates UTF-8, as does the visitor functions.&lt;/p&gt;

&lt;p&gt;Found that &lt;code&gt;BSON_CHECK_VERSION&lt;/code&gt; is incorrectly documented. "is greater than" should be "is greater than or equal to". Fixed with (&lt;a href="https://github.com/mongodb/mongo-c-driver/pull/1219"&gt;https://github.com/mongodb/mongo-c-driver/pull/1219&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Answer Open Questions
&lt;/h2&gt;

&lt;p&gt;As I read through API, I wrote down many open questions and answered them with tests:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Q: Does &lt;code&gt;bson_append_array&lt;/code&gt; reject documents with non integer string keys?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A: No. But &lt;code&gt;bson_append_array&lt;/code&gt; warns if the first key is not "0".&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Q: Does &lt;code&gt;bson_append_utf8&lt;/code&gt; error if given invalid UTF-8? A: No.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Q: If the default &lt;code&gt;bson_context_t&lt;/code&gt; is used, is a child process likely to produce the same &lt;code&gt;bson_oid_t&lt;/code&gt;?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A: No. The default &lt;code&gt;bson_context_t&lt;/code&gt; disables the PID cache.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Q: Does the max len option of &lt;code&gt;bson_json_opts_new&lt;/code&gt; produce invalid UTF-8 characters if on multi-byte character boundary? A: Yes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Q: Does &lt;code&gt;bson_concat&lt;/code&gt; support self-concatenation? A: Yes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Q: Can &lt;code&gt;bson_iter_find_descendant&lt;/code&gt; and &lt;code&gt;bson_iter_recurse&lt;/code&gt; use the same iterator for input and output? A: Yes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Q: Will parsing an integer value in JSON promote to int64 if it does not fit in int32? A: Yes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Q: How does &lt;code&gt;bson_string_t&lt;/code&gt; grow allocations? A: By power of 2.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Learn more C
&lt;/h2&gt;

&lt;p&gt;Learned about &lt;code&gt;static&lt;/code&gt; keyword applied to array sizes: &lt;a href="https://hamberg.no/erlend/posts/2013-02-18-static-array-indices.html"&gt;https://hamberg.no/erlend/posts/2013-02-18-static-array-indices.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Learned that &lt;code&gt;aligned_alloc&lt;/code&gt; requires alignment to be a power of &lt;code&gt;2 &amp;gt;= sizeof(void*)&lt;/code&gt;, and memory requested be a multiple of alignment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I think this was a valuable time investment.&lt;/p&gt;

&lt;p&gt;For further reading, I recommend David Golden's &lt;a href="https://xdg.me/learn-a-new-codebase/"&gt;A better way to learn a new codebase&lt;/a&gt;. That article inspired this idea.&lt;/p&gt;

</description>
      <category>c</category>
      <category>testing</category>
    </item>
    <item>
      <title>"Specify /EHsc" warning</title>
      <dc:creator>Kevin Albertson</dc:creator>
      <pubDate>Mon, 20 Feb 2023 01:01:45 +0000</pubDate>
      <link>https://dev.to/kevinalbs/specify-ehsc-warning-130a</link>
      <guid>https://dev.to/kevinalbs/specify-ehsc-warning-130a</guid>
      <description>&lt;p&gt;Using cmake to build C++ with custom &lt;code&gt;CMAKE_CXX_FLAGS&lt;/code&gt; on MSVC may result in a warning to &lt;code&gt;Specify /EHsc&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here is an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cmake"&gt;&lt;code&gt;&lt;span class="c1"&gt;# CMakeLists.txt&lt;/span&gt;

&lt;span class="nb"&gt;cmake_minimum_required&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;VERSION 3.23&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;project&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;ehsc&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;add_executable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;ehsc ehsc.cpp&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ehsc.cpp&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;NeedsDestruction&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="n"&gt;NeedsDestruction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Constructor called"&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;NeedsDestruction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Destructor called"&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;throws&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;NeedsDestruction&lt;/span&gt; &lt;span class="n"&gt;nd&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"exception"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;exception&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"caught exception"&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure with a custom &lt;code&gt;CMAKE_CXX_FLAGS&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cmake &lt;span class="nt"&gt;-S&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;-Bcmake-build&lt;/span&gt; &lt;span class="nt"&gt;-DCMAKE_CXX_FLAGS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/Wall"&lt;/span&gt;
cmake &lt;span class="nt"&gt;--build&lt;/span&gt; cmake-build &lt;span class="nt"&gt;--target&lt;/span&gt; ehsc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Building results in many warnings suggesting to &lt;code&gt;Specify /EHsc&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why does specifying &lt;code&gt;CMAKE_CXX_FLAGS&lt;/code&gt; result in this warning? Because cmake specifies default flags for MSVC.&lt;br&gt;
Setting &lt;code&gt;CMAKE_CXX_FLAGS&lt;/code&gt; appears to have the side-effect of overwriting the default MSVC flags set by cmake.&lt;br&gt;
For example, if &lt;code&gt;CMAKE_CXX_FLAGS&lt;/code&gt; is not set, this is the output of printing &lt;code&gt;CMAKE_CXX_FLAGS&lt;/code&gt; with cmake 3.23.1 on my Windows machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CMAKE_CXX_FLAGS=/DWIN32 /D_WINDOWS /W3 /GR /EHsc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Excluding &lt;code&gt;/EHsc&lt;/code&gt; from the build flags appears particularly problematic. &lt;code&gt;/EHsc&lt;/code&gt; is the &lt;a href="https://learn.microsoft.com/en-us/cpp/cpp/exception-handling-in-visual-cpp?view=msvc-170" rel="noopener noreferrer"&gt;documented default&lt;/a&gt; for the exception handling model:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Use an /EH compiler option to specify the exception handling model to use in a C++ project. Standard C++ exception handling (/EHsc) is the default in new C++ projects in Visual Studio.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Without &lt;code&gt;/EHsc&lt;/code&gt;, the destructor in the example is not called when the exception is thrown. Executing does not print the expected &lt;code&gt;Destructor called&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;throws ... begin
Constructor called
caught exception
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>How I work</title>
      <dc:creator>Kevin Albertson</dc:creator>
      <pubDate>Sun, 12 Feb 2023 16:47:12 +0000</pubDate>
      <link>https://dev.to/kevinalbs/how-i-work-3j66</link>
      <guid>https://dev.to/kevinalbs/how-i-work-3j66</guid>
      <description>&lt;p&gt;Here is a sample timeline of my typical day:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv3r3svueiln1qbjuropj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv3r3svueiln1qbjuropj.png" alt="Typical day timeline" width="605" height="628"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Respond to Urgent Requests
&lt;/h1&gt;

&lt;p&gt;I start the day by responding to urgent requests. I check slack and e-mail and only respond if the request is urgent or fast to respond to. The less I can divide my attention the more effective I can be at completing the Daily Plan.&lt;/p&gt;

&lt;h1&gt;
  
  
  Make a Daily Plan
&lt;/h1&gt;

&lt;p&gt;The Daily plan is three items. The first item is the highest priority.&lt;/p&gt;

&lt;p&gt;Here is a sample Daily Plan written in the margin of a work notebook:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjaetz2yzqs8dmh5wgxmn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjaetz2yzqs8dmh5wgxmn.jpg" alt="Sample Daily Plan" width="800" height="1130"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Plan achievable tasks. It is better to err towards small achievable tasks, than have big tasks that go unfinished. The more you finish the Daily Plan, the more you will trust yourself to stick to your Daily Plan.&lt;/p&gt;

&lt;p&gt;For big tasks, I set daily tasks to spend time. E.g. if X is a task that will take several days, my daily task will be "Spend 30 minutes on X" rather than "Do X".&lt;/p&gt;

&lt;p&gt;Estimate to complete the Daily Plan with half of the time available in the day. E.g. if you are in meetings for 2 hours, you have 6 hours of working time. Estimate to spend 3 hours on the Daily Plan. This padding accounts for unexpected interruptions. If the Daily Plan is finished early, work on other backlog items.&lt;/p&gt;

&lt;h1&gt;
  
  
  Review Input Streams
&lt;/h1&gt;

&lt;p&gt;At the end of the day, I review a checklist of input streams. Streams are reviewed in order of urgency:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Slack. Respond to all messages.&lt;/li&gt;
&lt;li&gt;Github. Review quick low complexity code reviews.&lt;/li&gt;
&lt;li&gt;Calendar. Accept/decline/reschedule all invites for the next day.&lt;/li&gt;
&lt;li&gt;E-mail. Respond/archive/delete/label all e-mails. Non-urgent e-mails requiring a response are often labeled with "Later".&lt;/li&gt;
&lt;li&gt;TODO list.&lt;/li&gt;
&lt;li&gt;Jira.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After reviewing the checklist, I have the state in my head of all pending items. Make the Daily Plan for the next day.&lt;/p&gt;

&lt;p&gt;Here is a sample checklist to end the day, with the next day's Daily Plan:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmv1m2vjvhi33fn8rf7y7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmv1m2vjvhi33fn8rf7y7.jpg" alt="Sample checklist and next Daily Plan" width="800" height="1066"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
    </item>
    <item>
      <title>How I take notes</title>
      <dc:creator>Kevin Albertson</dc:creator>
      <pubDate>Thu, 02 Feb 2023 01:46:00 +0000</pubDate>
      <link>https://dev.to/kevinalbs/how-i-take-notes-229c</link>
      <guid>https://dev.to/kevinalbs/how-i-take-notes-229c</guid>
      <description>&lt;h1&gt;
  
  
  Keep notes close to code
&lt;/h1&gt;

&lt;p&gt;I keep notes in the same directory as code. This makes it easy to reach. Here is a sample for notes taken when working on Wireshark:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr8o4wgda69o4pcn65f8z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr8o4wgda69o4pcn65f8z.png" alt="Text notes in code directory" width="800" height="891"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The newest notes are at the top of the file. This results in less scrolling to see recent notes or add new notes.&lt;/p&gt;

&lt;p&gt;Each logical section is separated with the line containing &lt;code&gt;--&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I use a global &lt;code&gt;.gitignore_global&lt;/code&gt; to ignore this file from git. The file is named &lt;code&gt;KEVINALBS-README.md&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Keep TODO lists and Open Questions on paper
&lt;/h1&gt;

&lt;p&gt;I find hand writing TODO lists helpful. It permits checking off a TODO list item.&lt;/p&gt;

&lt;p&gt;I write Open Questions on paper in this format:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff50hghlrbhf0jjzzyfh8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff50hghlrbhf0jjzzyfh8.jpg" alt="Handwritten notes" width="800" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The "A:" with empty space means it is an open question. I check off the "Q:" when the question is answered. I think I am more likely to remember Open Questions when I hand write them. That cues me to look for answers if I see them. Hand writing is a larger barrier than typing. I am more likely to make a shorter and clearer question when hand writing. &lt;/p&gt;

&lt;h1&gt;
  
  
  Draft external communication
&lt;/h1&gt;

&lt;p&gt;I draft descriptions for Pull Requests in my text editor. This permits writing them as I work on code. Example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft7to8kfu4pjiw6gwsc54.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft7to8kfu4pjiw6gwsc54.png" alt="PR with description" width="800" height="670"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I draft descriptions for Jira tickets in my text editor. Jira does not have a "save draft" feature. And often I may not have all information, or time / energy to write a full ticket in one sitting.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>blockchain</category>
      <category>cryptocurrency</category>
    </item>
    <item>
      <title>Time box work</title>
      <dc:creator>Kevin Albertson</dc:creator>
      <pubDate>Sun, 29 Jan 2023 20:04:17 +0000</pubDate>
      <link>https://dev.to/kevinalbs/time-box-work-35go</link>
      <guid>https://dev.to/kevinalbs/time-box-work-35go</guid>
      <description>&lt;p&gt;I work as a technical lead. I started working remotely in 2020. My job permits flexible working hours. In the start of 2020, I worked for periods of varying hours interspersed with long breaks. I never felt like I was "done" with work. This schedule stressed me and made me less productive. This post describes habits that have helped me define work-life boundaries and best utilize my time working.&lt;/p&gt;

&lt;h1&gt;
  
  
  Work fairly
&lt;/h1&gt;

&lt;p&gt;Consider compensation. I am salaried and expected to work 40 hours a week. I uphold my agreement and work for 40 hours a week. During those 40 hours, I work to the best of my ability. If I need to work less, I request PTO. I may work more than 40 hours on exception if there is a need. Working more than 40 hours devalues my time.&lt;/p&gt;

&lt;p&gt;Working 8 hours a day gives a clear "done" criteria. Once I have worked 8 hours, I sign off. I have upheld my side of the agreement with work.&lt;/p&gt;

&lt;p&gt;One way to develop this habit is by tracking time. Another way to develop this habit is working a regular schedule.&lt;/p&gt;

&lt;h1&gt;
  
  
  Work a regular schedule
&lt;/h1&gt;

&lt;p&gt;I set a schedule of working 8:00am-4:30pm. Other employees can rely on me being online and responsive during my working hours. I set the working hours in Google Calendar. If meetings are scheduled outside of my working hours, I ask to reschedule.&lt;/p&gt;

&lt;p&gt;I take breaks to refresh. Between tasks, I get up and walk around for ~5 minutes. I take a 30 minute lunch. Lunch is scheduled on my calendar. I do not check slack or e-mail during lunch.&lt;/p&gt;

&lt;p&gt;I do not use working more than 40 hours as an excuse for working less than 40 hours the next week. I continue to work my regular schedule.&lt;/p&gt;

&lt;p&gt;One counterargument to consider: I have varying energy during the day. I have the most energy in the morning, and less in the afternoon. I may be more productive by taking a long nap in the afternoon, and working later in the evening. But also consider: why use all of the highest energy on work? If I only work when I have energy, I will have no energy left for my personal life. I prefer working for a continuous 8 hour period, signing off, then using my remaining energy in my personal life.&lt;/p&gt;

&lt;h1&gt;
  
  
  Time box tasks
&lt;/h1&gt;

&lt;p&gt;Time box tasks to clarify "done" criteria for tasks.&lt;/p&gt;

&lt;p&gt;Once the requirements are met, there are always optional improvements to make. I do the best work I can in the time allotted. Testing and self-reviewing code are requirements. Skipping tests may result in bugs that cost more time later. Skipping self-review may result in more time spent for my peers reviewing.&lt;/p&gt;

&lt;p&gt;For example: I am writing a test to compare byte output of a function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;ASSERT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;got&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;memcmp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;got&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That line took ~5 seconds to write. It meets the minimum requirements. If the assertion fails, it prints this message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FAIL:/home/kevin/code/test_c_driver/test-timebox.c:14  main()
  Condition 'got.len == expected.len &amp;amp;&amp;amp; 0 == memcmp(got.data, expected.data, expected.len)' failed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The message may be more helpful if the data is also printed on failure. I add that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="c1"&gt;// bytes_to_hex returns string for the hex representation of `in`.&lt;/span&gt;
&lt;span class="c1"&gt;// The returned string must be freed with `free`.&lt;/span&gt;
&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;bytes_to_hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;uint8_t&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;malloc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;hex_table&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"01234567890ABCDEF"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint8_t&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hex_table&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hex_table&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sc"&gt;'\0'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The assertion becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;ASSERTF&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;got&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;memcmp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;got&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="s"&gt;"got     : %s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;
        &lt;span class="s"&gt;"expected: %s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;bytes_to_hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;got&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;got&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;bytes_to_hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That took ~2 minutes. If the assertion fails, it prints this message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FAIL:/home/kevin/code/test_c_driver/test-timebox.c:33  main()
  Condition 'got.len == expected.len &amp;amp;&amp;amp; 0 == memcmp(got.data, expected.data, expected.len)' failed.
got     : 626E6E626172
expected: 666E6E626172
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That looks better. After refactoring other &lt;code&gt;ASSERTF&lt;/code&gt; statements, this becomes verbose. I write a macro to reduce the repetition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#define ASSERT_MEMEQUAL(got, expected)                                                             \
    ASSERTF(got.len == expected.len &amp;amp;&amp;amp; 0 == memcmp(got.data, expected.data, expected.len),         \
            "got     : %s\n"                                                                       \
            "expected: %s",                                                                        \
            bytes_to_hex(got.data, got.len), bytes_to_hex(expected.data, expected.len));
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the assert becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;ASSERT_MEMEQUAL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;got&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That took another ~30 seconds.&lt;/p&gt;

&lt;p&gt;The whole task took ~2 minutes 35 seconds. The extra effort added value. Good test assertion messages can save time diagnosing test failures later.&lt;/p&gt;

&lt;p&gt;This could further be improved. Tests with large data print large horizontal strings on failure. &lt;code&gt;bytes_to_hex&lt;/code&gt; could add newlines. Assert failures can print a side-by-side diff. I can audit other tests that compare bytes and use the new &lt;code&gt;ASSERT_MEMEQUAL&lt;/code&gt;. How far I go with improvements is informed by how much time I want to spend on this task.&lt;/p&gt;

&lt;h1&gt;
  
  
  Handling notifications
&lt;/h1&gt;

&lt;p&gt;Turn off notifications off-hours. Only check notifications off-hours if you are prepared to act on them.&lt;br&gt;
Example: I kick off a CI test run just before signing off. That night I feel anxious about the results and want to check. I want the tests to pass. But I ask myself, "If the tests failed, do I have energy to investigate?" The answer is "No". Checking the test results will not change my behavior in that moment. Seeing failing tests will stress me. So I do not check the results.&lt;/p&gt;

&lt;p&gt;Turn on notifications on-hours. For someone in on-call, on-hours may be 24 hours. Be responsive on-hours. Respond to direct messages with a specific ETA "I will investigate this afternoon" rather than a vague "I will investigate later". If you do not respond, the sender can check in at that time. If it is urgent, the sender can request you prioritize it sooner.&lt;/p&gt;

</description>
      <category>welcome</category>
    </item>
    <item>
      <title>Order of __init__ and __del__</title>
      <dc:creator>Kevin Albertson</dc:creator>
      <pubDate>Fri, 25 Nov 2022 14:02:34 +0000</pubDate>
      <link>https://dev.to/kevinalbs/order-of-init-and-del-3ppb</link>
      <guid>https://dev.to/kevinalbs/order-of-init-and-del-3ppb</guid>
      <description>&lt;p&gt;The order of calls to &lt;code&gt;__del__&lt;/code&gt; surprised me. In Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;A.__init__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__del__&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;A.__del__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;B&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;B.__init__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__del__&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;B.__del__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;B&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nf"&gt;fn &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
Produces this output:
A.__init__
B.__init__
A.__del__
B.__del__
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I expected &lt;code&gt;__del__&lt;/code&gt; to be called in reverse order (ABBA). The reverse order matches &lt;a href="https://isocpp.org/wiki/faq/dtors#order-dtors-for-locals" rel="noopener noreferrer"&gt;C++ behavior&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;An alternative to guarantee order is &lt;code&gt;__enter__&lt;/code&gt; and &lt;code&gt;__exit__&lt;/code&gt; and use of the &lt;code&gt;with&lt;/code&gt; block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__enter__&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;A.__enter__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__exit__&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exc_type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exc_val&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exc_tb&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;A.__exit__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;B&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__enter__&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;B.__enter__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__exit__&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exc_type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exc_val&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exc_tb&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;B.__exit__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;B&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="nf"&gt;fn &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
Produces this output:
A.__enter__
B.__enter__
B.__exit__
A.__exit__
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The standard &lt;a href="https://docs.python.org/dev/reference/compound_stmts.html#with" rel="noopener noreferrer"&gt;guarantees the order&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;With more than one item, the context managers are processed as if multiple with statements were nested:&lt;/p&gt;


&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;B&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;SUITE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;is semantically equivalent to:&lt;/p&gt;


&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nc"&gt;B&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;SUITE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

</description>
      <category>gratitude</category>
    </item>
    <item>
      <title>Things learned from K&amp;R C</title>
      <dc:creator>Kevin Albertson</dc:creator>
      <pubDate>Wed, 16 Nov 2022 13:12:31 +0000</pubDate>
      <link>https://dev.to/kevinalbs/things-learned-from-kr-c-3emg</link>
      <guid>https://dev.to/kevinalbs/things-learned-from-kr-c-3emg</guid>
      <description>&lt;h2&gt;
  
  
  Pointers
&lt;/h2&gt;

&lt;p&gt;Pointer arithmetic on &lt;code&gt;void *&lt;/code&gt; is not allowed since the size of pointed-to data is unknown.&lt;/p&gt;

&lt;p&gt;"dangling pointer" == points to a deleted object&lt;br&gt;
"wild pointer" == &lt;del&gt;points to uninitialized&lt;/del&gt; uninitialized pointer&lt;/p&gt;

&lt;p&gt;Converting from an array to a pointer loses size information&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;256&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="n"&gt;printf&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%zu&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;sizeof&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 256&lt;/span&gt;
&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;pstr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;printf&lt;/span&gt;  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%zu&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;sizeof&lt;/span&gt; &lt;span class="n"&gt;pstr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 4 or 8 (size of pointer). &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Memory management
&lt;/h2&gt;

&lt;p&gt;"static" == allocated at compile time&lt;br&gt;
"automatic" == allocated on the stack&lt;br&gt;
"dynamic" == allocated on the heap&lt;/p&gt;
&lt;h2&gt;
  
  
  Types of behavior
&lt;/h2&gt;

&lt;p&gt;"implementation-defined" == implementation must document. E.g. propagation of sign bit on &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; operation.&lt;br&gt;
"undefined behavior" == no requirements. E.g. signed overflow.&lt;br&gt;
"unspecified behavior" == two or more possible behaviors E.g. order of argument evaluation.&lt;br&gt;
"locale-specific behavior" == depends on local conventions. E.g. whether tolower returns true for characters other than 26 lowercase Latin letters.&lt;/p&gt;

&lt;p&gt;The number of bits in a byte is implementation defined.&lt;/p&gt;

&lt;p&gt;An assignment is an expression evaluating to the left-hand side. E.g. &lt;code&gt;(c = getchar())&lt;/code&gt; evaluates to &lt;code&gt;c&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;extern&lt;/code&gt; can be used inside a function definition. E.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;extern&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;External and static variables are initialized to 0.&lt;/p&gt;

&lt;p&gt;String literals cannot be modified. E.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"abc"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// not allowed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;C89 int division with negative numbers is implementation defined. &lt;code&gt;7 / -2&lt;/code&gt; can be &lt;code&gt;-3&lt;/code&gt; or &lt;code&gt;-4&lt;/code&gt; (round up or down). C99 defines as &lt;code&gt;-3&lt;/code&gt; (toss the decimal after division).&lt;/p&gt;

&lt;p&gt;If &lt;code&gt;fn&lt;/code&gt; is called but not declared, the compiler assumes it is defined as &lt;code&gt;int fn()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Arithmetic and comparison of pointers that do not point to the same array is undefined behavior (exception is one past the last element in the array).&lt;/p&gt;

&lt;p&gt;You may omit the first dimension of a multi-dimensional array in parameters. E.g. &lt;code&gt;void f(int arr[][13])&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;argv[argc]&lt;/code&gt; is &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sizeof&lt;/code&gt; does not require parenthesis for objects. &lt;code&gt;sizeof object&lt;/code&gt; vs. &lt;code&gt;sizeof (type name)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;C supports bit fields. The order of bits is implementation defined. E.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;unsigned&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;is_keyword&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;unsigned&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;is_extern&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;unsigned&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;is_static&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;printf format is &lt;code&gt;%[-][&amp;lt;width&amp;gt;][.][&amp;lt;precision&amp;gt;][h|l][&amp;lt;conversion&amp;gt;]&lt;/code&gt;. &lt;code&gt;&amp;lt;width&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;precision&amp;gt;&lt;/code&gt; may be &lt;code&gt;*&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;FILE*&lt;/code&gt; is OS independent. File descriptors are Unix specific.&lt;/p&gt;

</description>
      <category>c</category>
    </item>
    <item>
      <title>Bit shift wraps values</title>
      <dc:creator>Kevin Albertson</dc:creator>
      <pubDate>Fri, 19 Aug 2022 00:57:35 +0000</pubDate>
      <link>https://dev.to/kevinalbs/bit-shift-wraps-values-33f</link>
      <guid>https://dev.to/kevinalbs/bit-shift-wraps-values-33f</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;inttypes.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdint.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint32_t&lt;/span&gt; &lt;span class="n"&gt;shift&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;shift&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;shift&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint32_t&lt;/span&gt; &lt;span class="n"&gt;u32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;UINT32_MAX&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;printf&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"1 &amp;gt;&amp;gt; %02"&lt;/span&gt; &lt;span class="n"&gt;PRIu32&lt;/span&gt; &lt;span class="s"&gt;" = %"&lt;/span&gt; &lt;span class="n"&gt;PRIu32&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example may be run &lt;a href="https://godbolt.org/z/dErrjh918"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I expected that &lt;code&gt;UINT32_MAX &amp;gt;&amp;gt; 32&lt;/code&gt; to result in &lt;code&gt;0&lt;/code&gt;. But the output disagrees:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 &amp;gt;&amp;gt; 00 = 4294967295
1 &amp;gt;&amp;gt; 01 = 2147483647
1 &amp;gt;&amp;gt; 02 = 1073741823
1 &amp;gt;&amp;gt; 03 = 536870911
1 &amp;gt;&amp;gt; 04 = 268435455
1 &amp;gt;&amp;gt; 05 = 134217727
1 &amp;gt;&amp;gt; 06 = 67108863
1 &amp;gt;&amp;gt; 07 = 33554431
1 &amp;gt;&amp;gt; 08 = 16777215
1 &amp;gt;&amp;gt; 09 = 8388607
1 &amp;gt;&amp;gt; 10 = 4194303
1 &amp;gt;&amp;gt; 11 = 2097151
1 &amp;gt;&amp;gt; 12 = 1048575
1 &amp;gt;&amp;gt; 13 = 524287
1 &amp;gt;&amp;gt; 14 = 262143
1 &amp;gt;&amp;gt; 15 = 131071
1 &amp;gt;&amp;gt; 16 = 65535
1 &amp;gt;&amp;gt; 17 = 32767
1 &amp;gt;&amp;gt; 18 = 16383
1 &amp;gt;&amp;gt; 19 = 8191
1 &amp;gt;&amp;gt; 20 = 4095
1 &amp;gt;&amp;gt; 21 = 2047
1 &amp;gt;&amp;gt; 22 = 1023
1 &amp;gt;&amp;gt; 23 = 511
1 &amp;gt;&amp;gt; 24 = 255
1 &amp;gt;&amp;gt; 25 = 127
1 &amp;gt;&amp;gt; 26 = 63
1 &amp;gt;&amp;gt; 27 = 31
1 &amp;gt;&amp;gt; 28 = 15
1 &amp;gt;&amp;gt; 29 = 7
1 &amp;gt;&amp;gt; 30 = 3
1 &amp;gt;&amp;gt; 31 = 1
1 &amp;gt;&amp;gt; 32 = 4294967295
1 &amp;gt;&amp;gt; 33 = 2147483647
1 &amp;gt;&amp;gt; 34 = 1073741823
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;1 &amp;gt;&amp;gt; 32&lt;/code&gt; is undefined behavior by the C standard &lt;a href="https://port70.net/~nsz/c/c99/n1256.html#6.5.7"&gt;6.5.7&lt;/a&gt; of left shift:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;TIL&lt;/p&gt;

</description>
      <category>c</category>
    </item>
  </channel>
</rss>
