Git 基础 - 打标签
=Ditaa= Source Code Blocks in Org Mode

Convert enumerator names to string in C/C++

tubo posted @ 2014年11月06日 18:20 in 未分类 , 1231 阅读

From stackoverflow

Another way, making the preprocessor do the work. It also ensures your enums and strings are in sync.

#define FOREACH_FRUIT(FRUIT) \
        FRUIT(apple)   \
        FRUIT(orange)  \
        FRUIT(grape)   \
        FRUIT(banana)  \

#define GENERATE_ENUM(ENUM) ENUM,
#define GENERATE_STRING(STRING) #STRING,

enum FRUIT_ENUM {
    FOREACH_FRUIT(GENERATE_ENUM)
};

static const char *FRUIT_STRING[] = {
    FOREACH_FRUIT(GENERATE_STRING)
};

After the preprocessor gets done, you'll have:

enum FRUIT_ENUM {
    apple, orange, grape, banana,
};

static const char *FRUIT_STRING[] = {
    "apple", "orange", "grape", "banana",
};

Then you could do something like:

printf("enum apple as a string: %s\n",FRUIT_STRING[apple]);

Another way, if the use case is literally just printing the enum name:

#define str(x) #x
#define xstr(x) str(x)

Then do:

printf("enum apple as a string: %s\n", xstr(apple));

 

Fadden 说:
2019年4月01日 18:39

I have to convert those names with the all updates of the new to all old variant by the figure out depends to use. Generate about the strings on the custom essay writing services uk will not be figure it out actual in the genially.

Dignissimos dolor vo 说:
2019年7月24日 23:45

[essaymama.com review](https://www.essaywritingboo.com/essaymama-com-review/)

"school assignment help":https://www.essaywritinglab.co.uk/assignment/
[assignment writing help australia|https://myassignments-help.com.au/]
[[https://www.dissertationhqhelp.com/expert-writers-net-review-5-10/|expert writers reviews ]]

<a href="https://www.essaywritinglab.co.uk/" style="background-color: rgb(3, 255, 11); border: 1px dashed black;">paper writing service</a>

jaimeallen 说:
2019年8月30日 03:53

I was in the rubyfortune nz casino. I got some answers concerning this at the site. You can feel free to look into every one of the subtleties there, too.

alex 说:
2019年9月16日 03:02

hey i am doing a work for backlink 50 comment only for 5$ in one or two days for the website go to https://www.fiverr.com/alex5478/do-50-backlink-comment
thanks

Jerry 说:
2019年10月09日 22:42

If you want to win $5000 gift card for free then you must participate in the official <a href="https://www.homedepotcomsurveys.com/">homedepot.com survey</a> and win $5000 gift card for free. Home Depot store management is conducting this survey to their customers to take the feedback about their store and using that feedback they want to improve their services.

Jerry 说:
2019年10月09日 22:44

[url=www.google.com]google[/url]

Jerry 说:
2019年10月09日 22:48

If you want to win $5000 gift card for free then you must participate in the official <a href="https://www.homedepotcomsurveys.com/">homedepot.com survey</a> and win $5000 gift card for free. Home Depot store management is conducting this survey to their customers to take the feedback about their store and using that feedback they want to improve their services.

abrar 说:
2019年10月19日 01:28

If you want to win $5000 gift card for free then you must participate in the official <a href="https://www.homedepotcomsurveys.com/">homedepot.com survey</a> and win $5000 gift card for free. Home Depot store management is conducting this survey to their customers to take the feedback about their store and using that feedback they want to<a href="https://www.fiverr.com/alex5478/do-50-backlink-comment" style="font-size: 11px;" target="_self">backlinks</a>

abrar 说:
2019年11月01日 18:43

. I got some answers concerning this at the site. You can feel free to look into every one of the subtleties there, too
[url=https://www.fiverr.com/alex5478/do-50-backlink-comment]backlinks [/url]

jafir 说:
2020年2月01日 04:21

At that point along came the link organizations. Out of nowhere we could encounter radically improved nature of sound, video and obviously content, as they gave access to an a lot more extensive scope of channels. Binge

itsmonika 说:
2020年6月15日 22:37
C++ was my favorite subject all the time. I just found it difficult to understand the loop and run the loop but Assignment writing services did not let me down. I hired a tutor online, and he taught me very well about loops. 
 
backlinks 说:
2020年6月16日 05:11

Backlinking is only one bit of the total positioning algorithmic program for all the web search tools however is one of the key impacts in getting a webpage to rank impressively high guaranteeing it remains along these lines into what's to come. Dofollow backlinks

Dofollow backlinks 说:
2020年7月13日 10:01

So as to make effective backlinks, you have to manufacture connections. There are a ton of ways that individuals will take a shot at their backlinks, and a ton just requires contacts.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter