{"action":"created","comment":{"url":"https://api.github.com/repos/kaaproject/kaa/pulls/comments/71718582","id":71718582,"diff_hunk":"@@ -0,0 +1,191 @@\n+---\n+layout: page\n+title: C/C++\n+permalink: /:path/\n+sort_idx: 30\n+---\n+\n+* TOC\n+{:toc}\n+\n+The guide describes code formatting and coding rules that must be followed in Kaa C and C++ SDKs.\n+\n+There are few common and most important guidelines for both C and C++ SDK.\n+\n+- Use C99 for C code and C++11 for C++ code**\n+- Anything that causes the undefined behavior (according to C/C++ standarts) either in runtime or in compile-time is prohibited, even if at this point of time it is predictable.\n+E.g. signed integer overflow.\n+- Anything that relies on assumptions about unspecified behavior (according to C/C++ standarts) either in runtime or in compile-time is prohibited as well.\n+E.g. assuming that function arguments evaluate in particular order.\n+- Anything that relies on particular implementation-defined values, or semantically behaves differentely in different implementations should be marked and properly documented and allowed only in platform-dependent code of the Kaa SDK.\n+E.g. assuming that `int` will occupy 4 bytes on every platform.\n+\n+  ```c\n+  int *x = malloc(4); // Wrong! Size of integer is implementation-defined.\n+  ```\n+\n+# Code appearance in C\n+\n+- It is recommended to use a source formatting script against modified sources.\n+The script is placed in `client/client-multi/client-c/scripts/srcformat.sh`.\n+- Use 4 spaces for indentation. Don't use tabs.\n+- Use 100-character column width.\n+- Use `snake_case` for the names (not `camelCase`) in C code.\n+- All macro names must be in UPPERCASE.\n+- Use [1TBS](https://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS) (the one true brace style).\n+\n+  ```cpp\n+  int main(int argc, char *argv[])\n+  {\n+     if (argc > 2) {\n+         printf(\"too many args\\n\");\n+     } else {\n+         printf(\"too little args\\n\");\n+     }\n+\n+     return 0;\n+  }\n+  ```\n+\n+  Note brace position.\n+\n+- The braces in control structures are required even for a single statement.\n+- The pointer star must be aligned to the variable name.\n+\n+  ```cpp\n+  int *x;\n+  ```\n+\n+- Labels must be indented one level less than the normal indentation (except for case labels).\n+\n+  ```cpp\n+  int main(int argc, char *argv[])\n+  {\n+      switch (argc) {\n+          case 3:\n+              printf(\"hi\\n\");\n+\n+          default:\n+              goto fail;\n+      }\n+\n+      return 0;\n+\n+  fail:\n+      return 1;\n+  }\n+  ```\n+\n+- Prefer double-indent instead of alignment in conditions and argument lists.\n+\n+  ```cpp\n+  int my_function(int param1, int param2,\n+         int param3, int param4)\n+  {\n+      if (param1 > 3 && param2 > 3 &&\n+              param3 > 3 && param4 > 3) {\n+          return param1 + param2 + param3 +\n+                  param4;\n+      } else {\n+          return 0;\n+      }\n+  }\n+  ```\n+\n+- Don't allow trailing spaces or lines.\n+- Wrap complex macro in a `do { } while(0)` statement\n+\n+  ```c\n+  #define COMPLEX_MACRO(a, b, c) \\\n+      do { foo(a); bar(b); baz(c); } while(0)\n+  ```\n+\n+- Place comma on the same line as parameter name when wrap lines due to long function or parameter names\n+\n+  ```c\n+  // Good\n+  void function_with_many_params_and_long_name(long_name_param a,\n+          long_name_param b, long_name_param c, long_name_param d,\n+          long_name_param e, long_name_param f)\n+\n+\n+  // Bad\n+  void function_with_many_params_and_long_name(param a\n+                                              , param b\n+                                              , param c)\n+  ```\n+\n+- Commented out code is not allowed without great reason and notes.\n+Use git instead.\n+\n+- Do not use `_t` suffix for type names.\n+It is reserved by the compiler.\n+\n+- Avoid using TODO or FIXME.\n+If still necessarry, create an issue and place TODO in the code along with issue number and description as shown below.\n+\n+  ```c\n+  // TODO(KAA-xxx): short description\n+  ```\n+\n+# Semantics\n+\n+- Initialize all variables.\n+- Prefer declaration with initialization.\n+\n+  ```c\n+  int a = 10; // Good\n+  int b; // Bad\n+  ```\n+\n+- Initiailize structures with members declaration\n+\n+  ```c\n+  struct st {\n+      int a;\n+      int b;\n+      int c;\n+  };\n+\n+\n+  void foo(void)\n+  {\n+      struct st obj = {\n+          .a = 1,\n+          .b = 2,\n+          .c = 3,\n+      };\n+  }\n+\n+  ```\n+\n+- Typedefs that indicate size and signedness should be used in place of the basic numerical types.\n+E.g. `size_t` for holding objects sizes.","path":"doc/Customization-guide/Code-style/C-C++/index.md","position":163,"original_position":163,"commit_id":"c55b7629f5ad54328d80a6cbd930abbc957b6a8a","original_commit_id":"c55b7629f5ad54328d80a6cbd930abbc957b6a8a","user":{"login":"rasendubi","id":1366419,"avatar_url":"https://avatars.githubusercontent.com/u/1366419?v=3","gravatar_id":"","url":"https://api.github.com/users/rasendubi","html_url":"https://github.com/rasendubi","followers_url":"https://api.github.com/users/rasendubi/followers","following_url":"https://api.github.com/users/rasendubi/following{/other_user}","gists_url":"https://api.github.com/users/rasendubi/gists{/gist_id}","starred_url":"https://api.github.com/users/rasendubi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rasendubi/subscriptions","organizations_url":"https://api.github.com/users/rasendubi/orgs","repos_url":"https://api.github.com/users/rasendubi/repos","events_url":"https://api.github.com/users/rasendubi/events{/privacy}","received_events_url":"https://api.github.com/users/rasendubi/received_events","type":"User","site_admin":false},"body":"`size_t` is a different beast from `Typedefs that indicate size and signedness`. The later are `uint32_t`, int8_t`, etc.","created_at":"2016-07-21T14:42:50Z","updated_at":"2016-07-21T14:42:50Z","html_url":"https://github.com/kaaproject/kaa/pull/881#discussion_r71718582","pull_request_url":"https://api.github.com/repos/kaaproject/kaa/pulls/881","_links":{"self":{"href":"https://api.github.com/repos/kaaproject/kaa/pulls/comments/71718582"},"html":{"href":"https://github.com/kaaproject/kaa/pull/881#discussion_r71718582"},"pull_request":{"href":"https://api.github.com/repos/kaaproject/kaa/pulls/881"}}},"pull_request":{"url":"https://api.github.com/repos/kaaproject/kaa/pulls/881","id":77648398,"html_url":"https://github.com/kaaproject/kaa/pull/881","diff_url":"https://github.com/kaaproject/kaa/pull/881.diff","patch_url":"https://github.com/kaaproject/kaa/pull/881.patch","issue_url":"https://api.github.com/repos/kaaproject/kaa/issues/881","number":881,"state":"open","locked":false,"title":"KAA-1243 C/C++ code style guide","user":{"login":"forGGe","id":5261821,"avatar_url":"https://avatars.githubusercontent.com/u/5261821?v=3","gravatar_id":"","url":"https://api.github.com/users/forGGe","html_url":"https://github.com/forGGe","followers_url":"https://api.github.com/users/forGGe/followers","following_url":"https://api.github.com/users/forGGe/following{/other_user}","gists_url":"https://api.github.com/users/forGGe/gists{/gist_id}","starred_url":"https://api.github.com/users/forGGe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/forGGe/subscriptions","organizations_url":"https://api.github.com/users/forGGe/orgs","repos_url":"https://api.github.com/users/forGGe/repos","events_url":"https://api.github.com/users/forGGe/events{/privacy}","received_events_url":"https://api.github.com/users/forGGe/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-07-15T17:14:30Z","updated_at":"2016-07-21T14:42:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"59119158314c59c692e2312da19ed481cc5d51db","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/kaaproject/kaa/pulls/881/commits","review_comments_url":"https://api.github.com/repos/kaaproject/kaa/pulls/881/comments","review_comment_url":"https://api.github.com/repos/kaaproject/kaa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kaaproject/kaa/issues/881/comments","statuses_url":"https://api.github.com/repos/kaaproject/kaa/statuses/c55b7629f5ad54328d80a6cbd930abbc957b6a8a","head":{"label":"forGGe:KAA-1243_c_c++_code_style","ref":"KAA-1243_c_c++_code_style","sha":"c55b7629f5ad54328d80a6cbd930abbc957b6a8a","user":{"login":"forGGe","id":5261821,"avatar_url":"https://avatars.githubusercontent.com/u/5261821?v=3","gravatar_id":"","url":"https://api.github.com/users/forGGe","html_url":"https://github.com/forGGe","followers_url":"https://api.github.com/users/forGGe/followers","following_url":"https://api.github.com/users/forGGe/following{/other_user}","gists_url":"https://api.github.com/users/forGGe/gists{/gist_id}","starred_url":"https://api.github.com/users/forGGe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/forGGe/subscriptions","organizations_url":"https://api.github.com/users/forGGe/orgs","repos_url":"https://api.github.com/users/forGGe/repos","events_url":"https://api.github.com/users/forGGe/events{/privacy}","received_events_url":"https://api.github.com/users/forGGe/received_events","type":"User","site_admin":false},"repo":{"id":47995904,"name":"kaa","full_name":"forGGe/kaa","owner":{"login":"forGGe","id":5261821,"avatar_url":"https://avatars.githubusercontent.com/u/5261821?v=3","gravatar_id":"","url":"https://api.github.com/users/forGGe","html_url":"https://github.com/forGGe","followers_url":"https://api.github.com/users/forGGe/followers","following_url":"https://api.github.com/users/forGGe/following{/other_user}","gists_url":"https://api.github.com/users/forGGe/gists{/gist_id}","starred_url":"https://api.github.com/users/forGGe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/forGGe/subscriptions","organizations_url":"https://api.github.com/users/forGGe/orgs","repos_url":"https://api.github.com/users/forGGe/repos","events_url":"https://api.github.com/users/forGGe/events{/privacy}","received_events_url":"https://api.github.com/users/forGGe/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/forGGe/kaa","description":"Kaa open-source middleware platform for building, managing, and integrating connected products with the Internet of Everything.","fork":true,"url":"https://api.github.com/repos/forGGe/kaa","forks_url":"https://api.github.com/repos/forGGe/kaa/forks","keys_url":"https://api.github.com/repos/forGGe/kaa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/forGGe/kaa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/forGGe/kaa/teams","hooks_url":"https://api.github.com/repos/forGGe/kaa/hooks","issue_events_url":"https://api.github.com/repos/forGGe/kaa/issues/events{/number}","events_url":"https://api.github.com/repos/forGGe/kaa/events","assignees_url":"https://api.github.com/repos/forGGe/kaa/assignees{/user}","branches_url":"https://api.github.com/repos/forGGe/kaa/branches{/branch}","tags_url":"https://api.github.com/repos/forGGe/kaa/tags","blobs_url":"https://api.github.com/repos/forGGe/kaa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/forGGe/kaa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/forGGe/kaa/git/refs{/sha}","trees_url":"https://api.github.com/repos/forGGe/kaa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/forGGe/kaa/statuses/{sha}","languages_url":"https://api.github.com/repos/forGGe/kaa/languages","stargazers_url":"https://api.github.com/repos/forGGe/kaa/stargazers","contributors_url":"https://api.github.com/repos/forGGe/kaa/contributors","subscribers_url":"https://api.github.com/repos/forGGe/kaa/subscribers","subscription_url":"https://api.github.com/repos/forGGe/kaa/subscription","commits_url":"https://api.github.com/repos/forGGe/kaa/commits{/sha}","git_commits_url":"https://api.github.com/repos/forGGe/kaa/git/commits{/sha}","comments_url":"https://api.github.com/repos/forGGe/kaa/comments{/number}","issue_comment_url":"https://api.github.com/repos/forGGe/kaa/issues/comments{/number}","contents_url":"https://api.github.com/repos/forGGe/kaa/contents/{+path}","compare_url":"https://api.github.com/repos/forGGe/kaa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/forGGe/kaa/merges","archive_url":"https://api.github.com/repos/forGGe/kaa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/forGGe/kaa/downloads","issues_url":"https://api.github.com/repos/forGGe/kaa/issues{/number}","pulls_url":"https://api.github.com/repos/forGGe/kaa/pulls{/number}","milestones_url":"https://api.github.com/repos/forGGe/kaa/milestones{/number}","notifications_url":"https://api.github.com/repos/forGGe/kaa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/forGGe/kaa/labels{/name}","releases_url":"https://api.github.com/repos/forGGe/kaa/releases{/id}","deployments_url":"https://api.github.com/repos/forGGe/kaa/deployments","created_at":"2015-12-14T19:16:40Z","updated_at":"2016-03-30T14:50:20Z","pushed_at":"2016-07-21T14:33:47Z","git_url":"git://github.com/forGGe/kaa.git","ssh_url":"git@github.com:forGGe/kaa.git","clone_url":"https://github.com/forGGe/kaa.git","svn_url":"https://github.com/forGGe/kaa","homepage":"http://www.kaaproject.org","size":94962,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kaaproject:develop","ref":"develop","sha":"ce5a3109520569207ecc292bab77c5530f7e4000","user":{"login":"kaaproject","id":6984613,"avatar_url":"https://avatars.githubusercontent.com/u/6984613?v=3","gravatar_id":"","url":"https://api.github.com/users/kaaproject","html_url":"https://github.com/kaaproject","followers_url":"https://api.github.com/users/kaaproject/followers","following_url":"https://api.github.com/users/kaaproject/following{/other_user}","gists_url":"https://api.github.com/users/kaaproject/gists{/gist_id}","starred_url":"https://api.github.com/users/kaaproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaaproject/subscriptions","organizations_url":"https://api.github.com/users/kaaproject/orgs","repos_url":"https://api.github.com/users/kaaproject/repos","events_url":"https://api.github.com/users/kaaproject/events{/privacy}","received_events_url":"https://api.github.com/users/kaaproject/received_events","type":"Organization","site_admin":false},"repo":{"id":17839346,"name":"kaa","full_name":"kaaproject/kaa","owner":{"login":"kaaproject","id":6984613,"avatar_url":"https://avatars.githubusercontent.com/u/6984613?v=3","gravatar_id":"","url":"https://api.github.com/users/kaaproject","html_url":"https://github.com/kaaproject","followers_url":"https://api.github.com/users/kaaproject/followers","following_url":"https://api.github.com/users/kaaproject/following{/other_user}","gists_url":"https://api.github.com/users/kaaproject/gists{/gist_id}","starred_url":"https://api.github.com/users/kaaproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaaproject/subscriptions","organizations_url":"https://api.github.com/users/kaaproject/orgs","repos_url":"https://api.github.com/users/kaaproject/repos","events_url":"https://api.github.com/users/kaaproject/events{/privacy}","received_events_url":"https://api.github.com/users/kaaproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kaaproject/kaa","description":"Kaa open-source middleware platform for building, managing, and integrating connected products with the Internet of Everything.","fork":false,"url":"https://api.github.com/repos/kaaproject/kaa","forks_url":"https://api.github.com/repos/kaaproject/kaa/forks","keys_url":"https://api.github.com/repos/kaaproject/kaa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kaaproject/kaa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kaaproject/kaa/teams","hooks_url":"https://api.github.com/repos/kaaproject/kaa/hooks","issue_events_url":"https://api.github.com/repos/kaaproject/kaa/issues/events{/number}","events_url":"https://api.github.com/repos/kaaproject/kaa/events","assignees_url":"https://api.github.com/repos/kaaproject/kaa/assignees{/user}","branches_url":"https://api.github.com/repos/kaaproject/kaa/branches{/branch}","tags_url":"https://api.github.com/repos/kaaproject/kaa/tags","blobs_url":"https://api.github.com/repos/kaaproject/kaa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kaaproject/kaa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kaaproject/kaa/git/refs{/sha}","trees_url":"https://api.github.com/repos/kaaproject/kaa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kaaproject/kaa/statuses/{sha}","languages_url":"https://api.github.com/repos/kaaproject/kaa/languages","stargazers_url":"https://api.github.com/repos/kaaproject/kaa/stargazers","contributors_url":"https://api.github.com/repos/kaaproject/kaa/contributors","subscribers_url":"https://api.github.com/repos/kaaproject/kaa/subscribers","subscription_url":"https://api.github.com/repos/kaaproject/kaa/subscription","commits_url":"https://api.github.com/repos/kaaproject/kaa/commits{/sha}","git_commits_url":"https://api.github.com/repos/kaaproject/kaa/git/commits{/sha}","comments_url":"https://api.github.com/repos/kaaproject/kaa/comments{/number}","issue_comment_url":"https://api.github.com/repos/kaaproject/kaa/issues/comments{/number}","contents_url":"https://api.github.com/repos/kaaproject/kaa/contents/{+path}","compare_url":"https://api.github.com/repos/kaaproject/kaa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kaaproject/kaa/merges","archive_url":"https://api.github.com/repos/kaaproject/kaa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kaaproject/kaa/downloads","issues_url":"https://api.github.com/repos/kaaproject/kaa/issues{/number}","pulls_url":"https://api.github.com/repos/kaaproject/kaa/pulls{/number}","milestones_url":"https://api.github.com/repos/kaaproject/kaa/milestones{/number}","notifications_url":"https://api.github.com/repos/kaaproject/kaa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kaaproject/kaa/labels{/name}","releases_url":"https://api.github.com/repos/kaaproject/kaa/releases{/id}","deployments_url":"https://api.github.com/repos/kaaproject/kaa/deployments","created_at":"2014-03-17T18:48:31Z","updated_at":"2016-07-21T13:29:59Z","pushed_at":"2016-07-21T14:41:24Z","git_url":"git://github.com/kaaproject/kaa.git","ssh_url":"git@github.com:kaaproject/kaa.git","clone_url":"https://github.com/kaaproject/kaa.git","svn_url":"https://github.com/kaaproject/kaa","homepage":"http://www.kaaproject.org","size":147912,"stargazers_count":334,"watchers_count":334,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":126,"mirror_url":null,"open_issues_count":25,"forks":126,"open_issues":25,"watchers":334,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kaaproject/kaa/pulls/881"},"html":{"href":"https://github.com/kaaproject/kaa/pull/881"},"issue":{"href":"https://api.github.com/repos/kaaproject/kaa/issues/881"},"comments":{"href":"https://api.github.com/repos/kaaproject/kaa/issues/881/comments"},"review_comments":{"href":"https://api.github.com/repos/kaaproject/kaa/pulls/881/comments"},"review_comment":{"href":"https://api.github.com/repos/kaaproject/kaa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kaaproject/kaa/pulls/881/commits"},"statuses":{"href":"https://api.github.com/repos/kaaproject/kaa/statuses/c55b7629f5ad54328d80a6cbd930abbc957b6a8a"}}}}
{"actor":{"display_login":"rasendubi"}}