{"id":56244,"date":"2022-06-27T03:01:46","date_gmt":"2022-06-26T17:01:46","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=56244"},"modified":"2022-07-06T15:55:49","modified_gmt":"2022-07-06T05:55:49","slug":"webassembly-via-emscripten-and-c-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/webassembly-via-emscripten-and-c-primer-tutorial\/","title":{"rendered":"WebAssembly via Emscripten and C Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/fibonacci.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"WebAssembly via Emscripten and C Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/webassembly_c.gif\" title=\"WebAssembly via Emscripten and C Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">WebAssembly via Emscripten and C Primer Tutorial<\/p><\/div>\n<p>Have you done any web application work with a <a target=_blank title='WebAssembly Concepts ... thanks' href='https:\/\/developer.mozilla.org\/en-US\/docs\/WebAssembly\/Concepts'>WebAssembly<\/a>?  It gets you being able to bring your C or C++ or Rust code into a web application.  Great idea, huh?!  Today we&#8217;re presenting some simple usages of a WebAssembly made via two small pieces of C code &#8230;<\/p>\n<ul>\n<li>WebAssembly of <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/hello.html\" title=\"Click picture\">&#8220;Hello World&#8221;<\/a> via <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/hello.c_GETME\" title=\"hello.c\">hello.c<\/a> C code generating &#8230;\n<ol>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/hello.html_GETME\" title=\"hello.html\">hello.html<\/a><\/li>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/hello.js_GETME\" title=\"hello.js\">hello.js<\/a><\/li>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/hello.wasm_GETME\" title=\"hello.wasm\">hello.wasm<\/a><\/li>\n<p> &#8230; via Emscripten &#8230; thanks\n<\/ol>\n<p><iframe src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/hello.html\" title=\"Click picture\" style=\"width:100%;height:500px;\"><\/iframe>\n<\/li>\n<li>WebAssembly of <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/fibonacci.html\" title=\"Click picture\">Fibonacci series<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/fibonacci.html_GETME\" title=\"fibonacci.html\">fibonacci.html<\/a> via <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/main.c_GETME\" title=\"main.c\">main.c<\/a> C code generating &#8230;\n<ol>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/main.html_GETME\" title=\"main.html\">main.html<\/a><\/li>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/main.js_GETME\" title=\"main.js\">main.js<\/a><\/li>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/main.wasm_GETME\" title=\"main.wasm\">main.wasm<\/a><\/li>\n<p> &#8230; via Emscripten &#8230; thanks\n<\/ol>\n<p><input type=button onclick=\"document.getElementById('fibif').style.display='block'; document.getElementById('fibif').scrollIntoView(); \n document.getElementById('fibif').src='http:\/\/www.rjmprogramming.com.au\/Mac\/fibonacci.html'; \" value=\"Click for Emscripten Fibonacci series via C code\"><\/input><br \/>\n<iframe id=fibif src=\"http:\/\/www.rjmprogramming.com.au\/About_Us.html\" title=\"Click picture\" style=\"width:100%;height:900px;display:none;\"><\/iframe><span id=satend>&nbsp;<\/span>\n<\/li>\n<\/ul>\n<p>To get started, and going, here, we liked <a target=_blank title='Compiling a New C\/C++ Module to WebAssembly' href='https:\/\/developer.mozilla.org\/en-US\/docs\/WebAssembly\/C_to_wasm'>Compiling a New C\/C++ Module to WebAssembly<\/a> as far as advice goes and needed Emscripten download resources at <a target=_blank href='https:\/\/emscripten.org\/docs\/getting_started\/downloads.html' title='Emscripten Download and install'>Emscripten Download and install<\/a> and <a target=_blank title='CMake download and install' href='https:\/\/cmake.org\/download\/'>CMake<\/a> on our macOS local environment, allowing us to compile the html via a command such as &#8230;<\/p>\n<p><code><br \/>\nemcc hello.c -o hello.html<br \/>\n<\/code><\/p>\n<p> &#8230; allowing the sftp of the html and js and wasm over to the RJM Programming public web domain, and show you, in action, today.  Cute, huh, given the code is C by nature and inclination!<\/p>\n<p>Word of warning with the Fibonacci code is that use of C <a target=_blank title='C scanf function information' href='https:\/\/www.tutorialspoint.com\/c_standard_library\/c_function_scanf.htm'><i>scanf<\/i><\/a> function is a little sketchy in its behaviour, hence our wrapping of the Emscripten html within an iframe, where topmost parent html explains the issue, a bit.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d56244' onclick='var dv=document.getElementById(\"d56244\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/compile\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d56244' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Have you done any web application work with a WebAssembly? It gets you being able to bring your C or C++ or Rust code into a web application. Great idea, huh?! Today we&#8217;re presenting some simple usages of a WebAssembly &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/webassembly-via-emscripten-and-c-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,19,29,33,37],"tags":[176,233,234,241,4001,2184,495,576,611,2178,4022,4021,2976,997,999,1986,1034,1081,4003,1114,1166,1319,1402,4002],"class_list":["post-56244","post","type-post","status-publish","format-standard","hentry","category-elearning","category-installers","category-operating-system","category-software","category-tutorials","tag-c","tag-command","tag-command-line","tag-compile","tag-emscripten","tag-fibonacci","tag-github","tag-html","tag-install","tag-macos","tag-permission","tag-permissions","tag-privacy","tag-programming","tag-project","tag-proof-of-concept","tag-recursion","tag-rust","tag-scanf","tag-security","tag-software-2","tag-tutorial","tag-web-application","tag-webassembly"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/56244"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=56244"}],"version-history":[{"count":14,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/56244\/revisions"}],"predecessor-version":[{"id":56258,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/56244\/revisions\/56258"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=56244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=56244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=56244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}