{"id":14,"date":"2012-01-24T17:38:55","date_gmt":"2012-01-24T22:38:55","guid":{"rendered":"http:\/\/www.mcgurrin.com\/robots\/?p=14"},"modified":"2012-01-27T10:14:17","modified_gmt":"2012-01-27T15:14:17","slug":"a-note-on-c-c-and-arduino-programming","status":"publish","type":"post","link":"https:\/\/www.mcgurrin.info\/robots\/14\/","title":{"rendered":"A note on C, C++, and Arduino programming"},"content":{"rendered":"<p>I see a lot of questions on the Web about how Arduino code relates to C and\/or C++.\u00a0 In a nutshell,\u00a0 Arduino code IS basically C\/C++ code.\u00a0 Arduino uses a set of standard libraries to hide some of the functionality behind the curtain, making things easier for the newcomer to get started in the hobby.\u00a0 For example, rather than setting specific bits on a &#8220;Port&#8221; to identify a pin as an output, coding something like DDRC.1 = 1;\u00a0\u00a0 after looking up which &#8220;port register&#8221; and which bit in the register controls the pin you want, you simply can code something like:\u00a0 pinMode(8, OUTPUT);<\/p>\n<p>This can also save time and effort for more experienced developers as well.\u00a0 Arduino is not just for newbies.\u00a0 There are tradeoffs, however.\u00a0 For example, using the Arduino library to set pin modes takes longer, in terms of CPU processing time, than setting them more directly.\u00a0 BUT, because Arduino basically IS C, you can often (but not always) just drop in the direct code you need, and still use the Arduino libraries for the rest.\u00a0 And if you someday want to go straight to AVR C programming, skipping the Arduino IDE&#8217;s and libraries entirely, there are ways of doing that to with your Arduino board.<\/p>\n<p>You may have noticed that I said Arduino is basically C\/C++.\u00a0 Well, which is it?\u00a0 Aren&#8217;t they two different, if related languages?\u00a0 Yes, they are.\u00a0\u00a0 C++ is mostly a superset of C, adding <a href=\"http:\/\/altf.wordpress.com\/2010\/02\/15\/object-oriented-programming-explained-by-steve-jobs\/\">object oriented programming<\/a> concepts.\u00a0 C++ started as &#8220;C with classes&#8221; \u00a0 but C is no longer completely a proper subset of C++, as the two languages evolved a bit differently over time.\u00a0 These days, languages usually have both the core language itself and a set of standard libraries.\u00a0 These libraries have already coded frequently used routines in an efficient manner,\u00a0 so you don&#8217;t have to keep reinventing the wheel.\u00a0 As I understand it, Arduinos support C++ core language features and the common C libraries, such as math.h, but NOT the standard C++ libraries.\u00a0 So while you can use objects and other core C++ language features, you can&#8217;t draw from the C++ library.\u00a0 At least this is my understanding.\u00a0 Please let me know if I&#8217;ve gotten something wrong.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I see a lot of questions on the Web about how Arduino code relates to C and\/or C++.\u00a0 In a nutshell,\u00a0 Arduino code IS basically C\/C++ code.\u00a0 Arduino uses a set of standard libraries to hide some of the functionality &hellip; <a href=\"https:\/\/www.mcgurrin.info\/robots\/14\/\">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":[1],"tags":[3,12],"_links":{"self":[{"href":"https:\/\/www.mcgurrin.info\/robots\/wp-json\/wp\/v2\/posts\/14"}],"collection":[{"href":"https:\/\/www.mcgurrin.info\/robots\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mcgurrin.info\/robots\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mcgurrin.info\/robots\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mcgurrin.info\/robots\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":4,"href":"https:\/\/www.mcgurrin.info\/robots\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":26,"href":"https:\/\/www.mcgurrin.info\/robots\/wp-json\/wp\/v2\/posts\/14\/revisions\/26"}],"wp:attachment":[{"href":"https:\/\/www.mcgurrin.info\/robots\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mcgurrin.info\/robots\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mcgurrin.info\/robots\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}