<?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: Pin Loon Lee</title>
    <description>The latest articles on DEV Community by Pin Loon Lee (@pllee4).</description>
    <link>https://dev.to/pllee4</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%2F873268%2F0c88ae59-c8aa-4d72-a98e-7231814bab50.png</url>
      <title>DEV Community: Pin Loon Lee</title>
      <link>https://dev.to/pllee4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pllee4"/>
    <language>en</language>
    <item>
      <title>Github action to automatically push to another repository</title>
      <dc:creator>Pin Loon Lee</dc:creator>
      <pubDate>Sun, 18 Sep 2022 09:24:08 +0000</pubDate>
      <link>https://dev.to/pllee4/github-action-to-automatically-push-to-another-repository-2cc6</link>
      <guid>https://dev.to/pllee4/github-action-to-automatically-push-to-another-repository-2cc6</guid>
      <description>&lt;h1&gt;
  
  
  Github action to automatically push to another repository
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pOTQ4PCM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2AQBe0R0F4jfMeucKz" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pOTQ4PCM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2AQBe0R0F4jfMeucKz" alt="cover" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have you ever had the need for some of your repository to automatically push the content to another repository?&lt;/p&gt;

&lt;p&gt;There may be couple of reason for this, perhaps your main repository is not yet shareable or you would like to keep some content out of the other repository, perhaps you wish to keep the main repository private while acting as a centralized repository to control contents that are private and partially public.&lt;/p&gt;

&lt;p&gt;Since I have just started to write post in &lt;a href="https://pinloon.medium.com"&gt;Medium&lt;/a&gt; recently, I had the need to do so when I wish to organize the posts in a better manner. To ease my life of writing post, I have been using Github &lt;a href="https://github.com/protiumx/blogpub"&gt;action&lt;/a&gt; from &lt;code&gt;Brian Mayo&lt;/code&gt; to automatically publish the post to Medium. All I have to do is just writting down the post using Markdown format and push to Github. The blog repository has always been publicly available as it is also acting as a storage space for the sample codes used in the post.&lt;/p&gt;

&lt;p&gt;Nevertheless, when I realized there might be someday when some of the post may be only accessible by Medium members, I should keep the content private in a separate repository while enabling the codes used in the post to be publicly available. After considering git submodule, encrypted markdown, I have decided to keep current blog repository (that contains both post and code) private,  while having an additional Github's action to export only the shared code to another public repository.&lt;/p&gt;

&lt;p&gt;That is when I found Github &lt;a href="https://github.com/cpina/github-action-push-to-another-repository"&gt;action&lt;/a&gt; from &lt;code&gt;Carles Pina Estany&lt;/code&gt; useful for the case.&lt;/p&gt;

&lt;p&gt;To better illustrate, I have created &lt;a href="https://github.com/pllee4-Experimental/mock-medium-source"&gt;mock-medium-source&lt;/a&gt; and &lt;a href="https://github.com/pllee4-Experimental/mock-medium-output"&gt;mock-medium-output&lt;/a&gt; to mock my use case.&lt;/p&gt;

&lt;p&gt;From the &lt;code&gt;mock-medium-source&lt;/code&gt;, the file structure is as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── .github
│   ├── workflows
│   │   ├── medium-publish.yml
├── posts
│   ├── 001
│   │   ├── files
│   │   │   ├── Makefile
│   │   │   ├── mock.cpp
│   │   ├── post1.md
│   ├── 002
│   │   ├── files
│   │   │   ├── Makefile
│   │   ├── note.txt
│   │   ├── post2.md
├── README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The post in Medium would be originated from &lt;code&gt;.md&lt;/code&gt; files while the rest of the content under &lt;code&gt;posts/&amp;lt;number&amp;gt;&lt;/code&gt; would be reference code or information about the post.&lt;/p&gt;

&lt;p&gt;Hence, the thing that I shall keep private would be the markdown file as the shared code would be less meaningful without the content of the post. Although &lt;a href="https://gist.github.com/"&gt;Github Gist&lt;/a&gt; is a popular way to share code and snippets, at this moment I still prefer to keep code in a single place together with &lt;code&gt;Makefile&lt;/code&gt; or &lt;code&gt;CMakeLists.txt&lt;/code&gt; to ease compilation and running of code. I did not use any fancy operation to filter out those private content from &lt;code&gt;mock-medium-source&lt;/code&gt; before pushing &lt;code&gt;mock-medium-output&lt;/code&gt;, currently it is just a simple deleting of those markdown files before pushing to other repository.&lt;/p&gt;

&lt;p&gt;The expected file structure of &lt;code&gt;mock-medium-output&lt;/code&gt; repository would be just&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── posts
│   ├── 001
│   │   ├── files
│   │   │   ├── Makefile
│   │   │   ├── mock.cpp
│   ├── 002
│   │   ├── files
│   │   │   ├── Makefile
│   │   ├── note.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The yaml file for Github workflow in &lt;code&gt;mock-medium-source&lt;/code&gt; is as below, (remember to create secrets for the &lt;code&gt;SSH_DEPLOY_KEY&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;name: Publish to Medium

"on":
  push:
    branches:
      - master
    paths:
      - 'posts/**'

jobs:
  post:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Creates output folder and remove markdown
        run:  |
              mkdir output
              rm -rf posts/*/*.md
              cp -r posts output
      - name: Pushes to public repository
        id: push_directory
        uses: cpina/github-action-push-to-another-repository@ssh-deploy-key
        env:
          SSH_DEPLOY_KEY: ${{ secrets.WORKFLOW_DEPLOY_KEY }}
        with:
          source-directory: output/
          destination-github-username: 'pllee4-Experimental'
          destination-repository-name: 'mock-medium-output'
          user-email: pinloon_0428@hotmail.com
          commit-message: pushed from $GITHUB_REF
          target-branch: master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this yaml files, there are two things to be noted down&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The public repo &lt;code&gt;mock-medium-output&lt;/code&gt; must be created before it is able to be pushed from &lt;code&gt;mock-medium-source&lt;/code&gt;
&lt;em&gt;("created" means it is pushed with at least one commit in order to have a valid branch as target branch for the source repository)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;From the Github workflows, the path is &lt;code&gt;posts/**&lt;/code&gt;, that means the running of the workflows of &lt;code&gt;mock-medium-source&lt;/code&gt; would only be triggered when there is changes on the directory under &lt;code&gt;posts&lt;/code&gt;. This makes sense for my usage, however you could remove this part if you wish to.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is it! I can continue writing post using markdown format and have the workflows automatically push the relevant public content to be shared with you!&lt;/p&gt;

&lt;p&gt;Thanks and hope this is helpful for you!&lt;/p&gt;

</description>
      <category>blogging</category>
    </item>
    <item>
      <title>Perfect forwarding</title>
      <dc:creator>Pin Loon Lee</dc:creator>
      <pubDate>Sat, 13 Aug 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/pllee4/perfect-forwarding-482f</link>
      <guid>https://dev.to/pllee4/perfect-forwarding-482f</guid>
      <description>&lt;h1&gt;
  
  
  Perfect forwarding
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CD-2QH5J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.unsplash.com/photo-1592739212768-2f4726c714de%3Futm_medium%3Dmedium%26w%3D700%26q%3D50%26auto%3Dformat" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CD-2QH5J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.unsplash.com/photo-1592739212768-2f4726c714de%3Futm_medium%3Dmedium%26w%3D700%26q%3D50%26auto%3Dformat" alt="cover" width="700" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What is meant by perfect forwarding?&lt;/p&gt;

&lt;p&gt;"Forwarding" is the process where one function &lt;em&gt;forwards&lt;/em&gt; its parameter to another function.&lt;br&gt;
When it is perfect, the function should receive the same object passed from the function that does the forwarding.&lt;/p&gt;

&lt;p&gt;In other words, perfect forwarding means we do not just forward objects, we also forward their salient properties, whether they are lvalues or rvalues, const or volatile. &lt;/p&gt;

&lt;p&gt;Do not worry too much about the definition, we will go through some simple examples.&lt;/p&gt;

&lt;p&gt;Let say we have a simple class as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Object {
 public:
  Object() = default;

  void SetName(const std::string &amp;amp;name) { name_ = std::move(name); }
  std::string GetName() const { return name_; }

 private:
  std::string name_;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have also few overloaded functions named &lt;code&gt;UseObject&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;void UseObject(Object &amp;amp;) {
  std::cout &amp;lt;&amp;lt; "calling UseObject(Object &amp;amp;)" &amp;lt;&amp;lt; std::endl;
}

void UseObject(const Object &amp;amp;) {
  std::cout &amp;lt;&amp;lt; "calling UseObject(const Object &amp;amp;)" &amp;lt;&amp;lt; std::endl;
}

void UseObject(Object &amp;amp;&amp;amp;) {
  std::cout &amp;lt;&amp;lt; "calling UseObject(Object &amp;amp;&amp;amp;)" &amp;lt;&amp;lt; std::endl;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have the main&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {
  Object object;
  const Object const_object;
  UseObject(object);
  UseObject(const_object);
  UseObject(std::move(object));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which would produce the output as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;calling UseObject(Object &amp;amp;)
calling UseObject(const Object &amp;amp;)
calling UseObject(Object &amp;amp;&amp;amp;)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Right now, let say we have a simple template function that tries to pass the argument to &lt;code&gt;UseObject&lt;/code&gt; function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template &amp;lt;typename T&amp;gt;
void NotForwardToUseObject(T x) {
  UseObject(x);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, running of code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {
  Object object;
  const Object const_object;
  NotForwardToUseObject(object);
  NotForwardToUseObject(const_object);
  NotForwardToUseObject(std::move(object));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;would result in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;calling UseObject(Object &amp;amp;)
calling UseObject(Object &amp;amp;)
calling UseObject(Object &amp;amp;)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where functions are not called accordingly as what we have expected earlier.&lt;/p&gt;

&lt;p&gt;This is due to the &lt;code&gt;const&lt;/code&gt; and &lt;code&gt;rvalueness&lt;/code&gt; being ignored by the template deduction for &lt;code&gt;void NotForwardToUseObject(T x)&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;To deal with reference parameters, we have to use universal references, because only universal reference parameters encode information about the lvalueness and rvalueness of the arguments that are passed to them.&lt;/p&gt;

&lt;p&gt;Now if we use universal reference for template argument,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template &amp;lt;typename T&amp;gt;
void HalfForwardToUseObject(T &amp;amp;&amp;amp;x) {  // universal reference
  UseObject(x);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running of code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {
  Object object;
  const Object const_object;
  HalfForwardToUseObject(object);
  HalfForwardToUseObject(const_object);
  HalfForwardToUseObject(std::move(object));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;would result in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;calling UseObject(Object &amp;amp;)
calling UseObject(const Object &amp;amp;)
calling UseObject(Object &amp;amp;)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Almost! Forwarding of &lt;code&gt;const&lt;/code&gt; seems working but &lt;code&gt;rvalueness&lt;/code&gt; of the argument still not getting forwarded correctly.&lt;/p&gt;

&lt;p&gt;To have a true perfect forwarding, we have to cast &lt;code&gt;x&lt;/code&gt; to its original type and lvalue- or r-value-ness&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template &amp;lt;typename T&amp;gt;
void ForwardToUseObject(T &amp;amp;&amp;amp;x) {
  UseObject(static_cast&amp;lt;T &amp;amp;&amp;amp;&amp;gt;(x));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, running of code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {
  Object object;
  const Object const_object;
  ForwardToUseObject(object);
  ForwardToUseObject(const_object);
  ForwardToUseObject(std::move(object));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;would result in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;calling UseObject(Object &amp;amp;)
calling UseObject(const Object &amp;amp;)
calling UseObject(Object &amp;amp;&amp;amp;)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfect! We have successfully passed the object properly.&lt;br&gt;
To simplify the code, we can use &lt;code&gt;std::forward&lt;/code&gt; from C++ &lt;code&gt;&amp;lt;utility&amp;gt;&lt;/code&gt; library,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template &amp;lt;typename T&amp;gt;
void PerfectForwardToUseObject(T &amp;amp;&amp;amp;x) {
  UseObject(std::forward&amp;lt;T&amp;gt;(x));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope with the examples above, now you have understand what is meant by perfect forwarding.&lt;br&gt;
As usual, the code above is accessible from my &lt;a href="https://github.com/pllee4/blog-public/tree/master/posts/003/files"&gt;github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading till the end of the post!&lt;/p&gt;

</description>
      <category>blogging</category>
      <category>moderncplusplus</category>
    </item>
    <item>
      <title>Hello world!</title>
      <dc:creator>Pin Loon Lee</dc:creator>
      <pubDate>Fri, 10 Jun 2022 04:25:22 +0000</pubDate>
      <link>https://dev.to/pllee4/hello-world-2k5b</link>
      <guid>https://dev.to/pllee4/hello-world-2k5b</guid>
      <description>&lt;h1&gt;
  
  
  Hello world!
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UWky4rb4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.unsplash.com/photo-1633989464081-16ccd31287a1%3Futm_medium%3Dmedium%26w%3D700%26q%3D50%26auto%3Dformat" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UWky4rb4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.unsplash.com/photo-1633989464081-16ccd31287a1%3Futm_medium%3Dmedium%26w%3D700%26q%3D50%26auto%3Dformat" alt="cover" width="700" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hello world! I believe this is what a normal beginner for programming would see as they first try to code in certain programming language.&lt;/p&gt;

&lt;p&gt;As this is also my very first post in Dev, I would like to say &lt;code&gt;Hello world!&lt;/code&gt; too!&lt;/p&gt;

&lt;p&gt;As a C/C++ programmer, a simple program as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;

int main(int argc, char **argv) { 
  std::cout &amp;lt;&amp;lt; "Hello world!" &amp;lt;&amp;lt; std::endl; 
  return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;would provide the output of&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nevertheless, it would be boring if we only able to produce the output by using the sample above especially in the world of C/C++ where we should know everything in detail underlying the code.&lt;/p&gt;

&lt;p&gt;To do that, we will compile the code in a bare metal version using inline assembly language.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inline assembly language
&lt;/h2&gt;

&lt;p&gt;One of the way is to have &lt;code&gt;helloworld.c&lt;/code&gt; as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main(void) {
  register int    syscall_no  asm("rax") = 1;
  register int    arg1        asm("rdi") = 1;
  register char*  arg2        asm("rsi") = "Hello world!\n";
  register int    arg3        asm("rdx") = 13;
  asm("syscall");
  return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The system call number is put in register &lt;code&gt;rax&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The rest of the arguments are put in registers &lt;code&gt;rdi&lt;/code&gt;, &lt;code&gt;rsi&lt;/code&gt; and &lt;code&gt;rdx&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;%rdi, %rsi, %rdx, %rcx, %r8, and %r9 are used to pass the first six integer
or pointer parameters to called functions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words, the code above is executing the system call of&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;write(STDOUT_FILENO,
   "Hello world!\n",
   sizeof("Hello world!\n")
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Running of code under Linux x86-x64
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gcc &lt;span class="nt"&gt;-o&lt;/span&gt; helloworld helloworld.c
&lt;span class="nv"&gt;$ &lt;/span&gt;./helloworld
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Program without main
&lt;/h2&gt;

&lt;p&gt;To make more fun, we are going to write code that does not have &lt;code&gt;main&lt;/code&gt;, let's call it &lt;code&gt;nomain&lt;/code&gt; program&lt;/p&gt;

&lt;p&gt;The entry point for the program would be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void nomain() {
  print();
  exit();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where the &lt;code&gt;print&lt;/code&gt; and &lt;code&gt;exit&lt;/code&gt; functions would be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void print() {
  register char* arg2 asm("rsi") = "Hello world!\n";
  asm("mov $1,%%rax \n\t"
      "mov $1,%%rdi \n\t"
      "mov $13,%%rdx \n\t"
      "syscall \n\t" ::
          : "rdi", "rdx");
}

void exit() {
  asm("mov $0,%rdi \n\t"
      "mov $60,%rax \n\t"
      "syscall \n\t");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The print function is similar as the example described just now. For the &lt;code&gt;exit()&lt;/code&gt; function, it is executing system call of&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exit(EXIT_SUCCESS);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with return code &lt;strong&gt;0&lt;/strong&gt;, while &lt;strong&gt;60&lt;/strong&gt; is system call number for &lt;code&gt;exit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To check the return code, we can type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after executing the executable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Running of nomain code under Linux x86-x64
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gcc &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="nt"&gt;-fno-builtin&lt;/span&gt; helloworld.c
&lt;span class="nv"&gt;$ &lt;/span&gt;ld &lt;span class="nt"&gt;-static&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; nomain &lt;span class="nt"&gt;-o&lt;/span&gt; helloworld helloworld.o
&lt;span class="nv"&gt;$ &lt;/span&gt;./helloworld
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GCC&lt;/strong&gt; has provided a lot of built-in functions, normally it would replace C function with internal function of compiler for optimization purposes. For example, if only strings are involved in the &lt;code&gt;printf&lt;/code&gt; function, it would be replaced with &lt;code&gt;puts&lt;/code&gt; function to save time for formatting interpretation. &lt;code&gt;exit()&lt;/code&gt; function is one of the internal function for &lt;strong&gt;GCC&lt;/strong&gt;, hence we have to put &lt;code&gt;no-builtin&lt;/code&gt; flag to disable the built-in functions &lt;/li&gt;
&lt;li&gt;The entry point is then configured through &lt;code&gt;-e nomain&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading my very first post, hope you enjoy the reading!&lt;/p&gt;

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