<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8587207309123089456</id><updated>2024-09-14T08:11:58.787-07:00</updated><category term="C"/><category term="C Programming"/><category term="History"/><category term="Programming"/><category term="enum"/><title type='text'>C - Programming</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://learn-c-program.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8587207309123089456/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://learn-c-program.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Dino</name><uri>http://www.blogger.com/profile/03109667773998688312</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8587207309123089456.post-7690186251565798663</id><published>2015-09-11T04:50:00.009-07:00</published><updated>2020-08-23T12:00:33.713-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="enum"/><title type='text'>printing enum as string</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
While coding C programming, there will be scenarios where you want to print the enum values as string while debugging. There are methods where you can define separate function which will return the string of definition, but the issue with that is , when you edit code, if we add a new enum value and forgot to add in the string conversion function/array, it will be give lot of problems and spend time on debugging&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
After googling, i found on solution which has only one definition, I edited it to suit my requirements. Please check the code below&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;#define FOREACH_WEEKDAYS(WEEKDAYS) \&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WEEKDAYS(SUNDAY)&amp;nbsp; &amp;nbsp;\&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WEEKDAYS(MONDAY)&amp;nbsp; \&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WEEKDAYS(TUESDAY)&amp;nbsp; &amp;nbsp;\&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WEEKDAYS(WEDNESDAY)&amp;nbsp; \&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WEEKDAYS(THURSDAY)&amp;nbsp; \&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WEEKDAYS(FRIDAY)&amp;nbsp; \&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WEEKDAYS(SATURDAY)&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;#define GENERATE_ENUM(ENUM) ENUM,&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;#define GENERATE_STRING(STRING) #STRING,&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;enum WEEKDAYS_ENUM {&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FOREACH_WEEKDAYS(GENERATE_ENUM)&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;};&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;static const char *GET_WEEKDAY_STRING[] = {&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FOREACH_WEEKDAYS(GENERATE_STRING)&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;};&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;int main()&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;{&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; printf(&quot;enum SUNDAYas a string: %s enum(int): %d\n&quot;, GET_WEEKDAY_STRING[SUNDAY], SUNDAY);&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; printf(&quot;enum TUESDAY as a string: %s enum(int): %d\n&quot;, GET_WEEKDAY_STRING[TUESDAY], TUESDAY);&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;u&gt;OUTPUT as below&lt;/u&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;enum SUNDAY as a string: SUNDAY enum(int): 0&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;enum TUESDAY as a string: TUESDAY enum(int): 2&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;The below code after the preprocessing will look like(gcc -E)&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;enum WEEKDAYS_ENUM {&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY,&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;};&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;static const char *GET_WEEKDAY_STRING[] = {&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;SUNDAY&quot;, &quot;MONDAY&quot;, &quot;TUESDAY&quot;, &quot;WEDNESDAY&quot;, &quot;THURSDAY&quot;, &quot;FRIDAY&quot;, &quot;SATURDAY&quot;,&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;};&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://learn-c-program.blogspot.com/feeds/7690186251565798663/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learn-c-program.blogspot.com/2015/09/printing-enum-as-string.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8587207309123089456/posts/default/7690186251565798663'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8587207309123089456/posts/default/7690186251565798663'/><link rel='alternate' type='text/html' href='http://learn-c-program.blogspot.com/2015/09/printing-enum-as-string.html' title='printing enum as string'/><author><name>Dino</name><uri>http://www.blogger.com/profile/03109667773998688312</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8587207309123089456.post-2768196297721819812</id><published>2011-11-21T21:49:00.001-08:00</published><updated>2011-11-21T22:30:23.331-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="History"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><title type='text'>History of C programming language</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
C (pronounced like the letter C) is a general-purpose computer 
programming language developed C (pronounced like the letter C) is a 
general-purpose computer programming language developed between 1969 and
 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with 
the Unix operating system. C was designed for implementing system 
software, but it became so popular that its widely used for developing 
portable application software.&lt;br /&gt;
&lt;br /&gt;
C came from Thompson&#39;s B language. The main intention of C language was 
to make more readable programming language than the assembly language, 
which was used for system programming, low level access to CPU/Sytem 
registers and all.&lt;br /&gt;
&lt;br /&gt;
C was the language which evolved to be the most popular langage of all 
time. It can be used for making system level, low level programming, 
high level programming, application programming, creating compilers etc&lt;br /&gt;
&lt;br /&gt;
The initial development of C occurred at AT&amp;amp;T Bell Labs between 1969 and 1973 according to Ritchie, the best creative period occurred in 1972. It was named &quot;C&quot; because its features were derived from an earlier language called &quot;B&quot;, which according to Ken Thompson was a stripped-down version of the BCPL programming language.&lt;br /&gt;
&lt;br /&gt;
The foundation of C is closely tied to the development of the Unix operating system, originally implemented in assembly language on a PDP-7 by Ritchie and Thompson, incorporating several ideas from colleagues. Eventually they chose to port the operating system to a PDP-11. B&#39;s inability to take advantage of some of the PDP-11&#39;s features, notably byte addressability, led to the development of an early version of C.&lt;br /&gt;
&lt;br /&gt;
The original PDP-11 version of the Unix system was developed in assembly language. By 1973, with the addition of struct types, the C language became powerful enough that a majority of of the Unix kernel was rewritten in C. This was one of the first operating system kernels implemented in a language other than assembly. (Earlier instances include the Multics system (written in PL/I), and MCP (Master Control Program) for the Burroughs B5000 written in ALGOL in 1961.) &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learn-c-program.blogspot.com/feeds/2768196297721819812/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learn-c-program.blogspot.com/2011/11/history-of-c-programming-language.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8587207309123089456/posts/default/2768196297721819812'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8587207309123089456/posts/default/2768196297721819812'/><link rel='alternate' type='text/html' href='http://learn-c-program.blogspot.com/2011/11/history-of-c-programming-language.html' title='History of C programming language'/><author><name>Dino</name><uri>http://www.blogger.com/profile/03109667773998688312</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>