{"id":9135,"date":"2019-11-04T11:15:28","date_gmt":"2019-11-04T10:15:28","guid":{"rendered":"https:\/\/blogs.mentor.com\/colinwalls\/?p=9135"},"modified":"2019-11-04T11:15:28","modified_gmt":"2019-11-04T10:15:28","slug":"programming-language-extensions","status":"publish","type":"post","link":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/2019\/11\/04\/programming-language-extensions\/","title":{"rendered":"Programming language extensions"},"content":{"rendered":"<p>Embedded systems code is mostly written in C and C++. Other languages are gaining popularity, but these two are still dominant. These languages have two interesting characteristics: they are very firmly standardized; neither was designed for embedded. The first point is OK &#8211; standardization cannot be a bad thing. The second point is odd; why are languages used for a purpose for which they were not designed? \u2026<!--more--><\/p>\n<p>As C++ is essentially a superset of C, I will focus my attention the latter, older language. C was designed as a systems programming language and was intended to avoid too much assembly language usage, whilst still providing power and flexibility. C predates the arrival of microprocessors and embedded systems, but, because it was so readily available and almost fit the bill, it was widely adopted in the early days of embedded systems programming.<\/p>\n<p>Although C was not designed for embedded, it came very close to fulfilling the needs of embedded developers and became widely adopted. Unsurprisingly, as standardization progressed, nothing was done to accommodate the needs of embedded developers, who were only a tiny subset of C developers. The few shortcomings in the language were quickly addressed by tool vendors by means of language extensions. Extending a very standardized language sounds foolish, but it was probably the only way forward to avoid resorting to assembly language.<\/p>\n<p>Typically [and this varied from one tool vendor to another] the extensions to the language were limited to 4 new keywords: asm, interrupt, packed and unpacked:<\/p>\n<p><strong>asm<\/strong> &#8211; This is not strictly an extension keyword. In the standard, it is reserved, but not defined. In embedded toolkits this keyword is implemented to enable assembly language inserts, thus avoiding complete functions written in assembler.<\/p>\n<p><strong>interrupt<\/strong> &#8211; This keyword is used to qualify a function definition and instructs the compiler to code the function as an interrupt service routine, with the appropriate context save and restore.<\/p>\n<p><strong>packed<\/strong> &#8211; Embedded C compilers normally have an option to determine how data it laid out in memory. One possibility is unpacked data, which takes up more space, but is quicker to access. This key word overrides the option and declares an object that is packed as efficiently into memory as possible, at the expense of access time.<\/p>\n<p><strong>unpacked<\/strong> &#8211; This keyword is the complete reverse of <strong>packed<\/strong>. It is used to specify an exception when the default has been set to compress data into memory.<\/p>\n<p>It should be noted that the use of both packed and unpacked in one program is very unlikely.<\/p>\n<p><a href=\"http:\/\/www.linkedin.com\/in\/colinwalls\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-6579\" src=\"http:\/\/s3-blogs.mentor.com\/colinwalls\/files\/2014\/01\/linkedin.png\" alt=\"\" width=\"40\" height=\"40\" \/><\/a><a href=\"https:\/\/twitter.com\/colin_walls\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-6583\" src=\"http:\/\/s3-blogs.mentor.com\/colinwalls\/files\/2014\/01\/twitter.png\" alt=\"\" width=\"40\" height=\"40\" \/><\/a><a href=\"https:\/\/www.facebook.com\/colinwalls.author\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-6591\" src=\"http:\/\/s3-blogs.mentor.com\/colinwalls\/files\/2014\/01\/facebook.png\" alt=\"\" width=\"40\" height=\"40\" \/><\/a><a href=\"http:\/\/blogs.mentor.com\/colinwalls\/\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-6599\" src=\"http:\/\/s3-blogs.mentor.com\/colinwalls\/files\/2014\/01\/wordpress.jpg\" alt=\"\" width=\"44\" height=\"44\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Embedded systems code is mostly written in C and C++. Other languages are gaining popularity, but these two are still&#8230;<\/p>\n","protected":false},"author":71677,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spanish_translation":"","french_translation":"","german_translation":"","italian_translation":"","polish_translation":"","japanese_translation":"","chinese_translation":"","footnotes":""},"categories":[1],"tags":[313,339,300,638,710,711],"industry":[],"product":[],"coauthors":[],"class_list":["post-9135","post","type-post","status-publish","format-standard","hentry","category-news","tag-c","tag-development-tools","tag-embedded-software","tag-interrupts","tag-packed","tag-unpacked"],"_links":{"self":[{"href":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts\/9135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/users\/71677"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/comments?post=9135"}],"version-history":[{"count":0,"href":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts\/9135\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/media?parent=9135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/categories?post=9135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/tags?post=9135"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/industry?post=9135"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/product?post=9135"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/coauthors?post=9135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}