{"id":4233,"date":"2021-06-03T13:20:02","date_gmt":"2021-06-03T04:20:02","guid":{"rendered":"https:\/\/www.chihayafuru.jp\/tech\/?p=4233"},"modified":"2025-12-21T08:54:44","modified_gmt":"2025-12-20T23:54:44","slug":"c-%e3%83%97%e3%83%aa%e3%83%97%e3%83%ad%e3%82%bb%e3%83%83%e3%82%b5%e6%bc%94%e7%ae%97%e5%ad%90","status":"publish","type":"post","link":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/archives\/4233","title":{"rendered":"[C\u8a00\u8a9e] \u30d7\u30ea\u30d7\u30ed\u30bb\u30c3\u30b5\u6f14\u7b97\u5b50"},"content":{"rendered":"<h3>1. \u6587\u5b57\u5217\u5316\u6f14\u7b97\u5b50 (#)<\/h3>\n<p>\u5b9f\u5f15\u6570\u3092\u30c0\u30d6\u30eb\u30af\u30aa\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u62ec\u308b<\/p>\n<p><!--more--><\/p>\n<h4>1.1. \u5b9f\u5f15\u6570\u3092\uff11\u3064\u5c55\u958b\u3059\u308b\u3060\u3051\u306e\u5358\u7d14\u306a\u4f8b<\/h4>\n<h5>1.1.1. \u30d7\u30ea\u30d7\u30ed\u30bb\u30c3\u30b5\u5c55\u958b\u524d<\/h5>\n<pre class=\"lang:c decode:true \" >#include &lt;stdio.h&gt;\r\n#define  string_macro_func(x)    #x\r\n\r\nint main() {\r\n    char* str = string_macro_func(Hello);\r\n    printf(\"%s\\n\", str);\r\n    return 0;\r\n}<\/pre>\n<h5>1.1.2. \u30d7\u30ea\u30d7\u30ed\u30bb\u30c3\u30b5\u5c55\u958b\u5f8c<\/h5>\n<pre class=\"lang:c decode:true \" >int main() {\r\n    char* str = \"Hello\";\r\n    printf(\"%s\\n\", str);\r\n    return 0;\r\n}<\/pre>\n<h4>1.2. \u7d44\u307f\u5408\u308f\u305b\u305f\u4f8b<\/h4>\n<h5>1.2.1. \u30d7\u30ea\u30d7\u30ed\u30bb\u30c3\u30b5\u5c55\u958b\u524d<\/h5>\n<pre class=\"lang:c decode:true \" >#include &lt;stdio.h&gt;\r\n\r\n#define  print_macro_func(x)    printf(\"%s\\n\", #x)\r\n\r\nint main() {\r\n    print_macro_func(Hello);\r\n    return 0;\r\n}<\/pre>\n<h5>1.2.2. \u30d7\u30ea\u30d7\u30ed\u30bb\u30c3\u30b5\u5c55\u958b\u5f8c<\/h5>\n<pre class=\"lang:c decode:true \" >int main() {\r\n    printf(\"%s\\n\", \"Hello\");\r\n    return 0;\r\n}<\/pre>\n<h3>2. \u30c8\u30fc\u30af\u30f3\u9023\u7d50\u6f14\u7b97\u5b50 (##)<\/h3>\n<p>\u30c8\u30fc\u30af\u30f3\uff08\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u4e0a\u306e\u540d\u524d\uff09\u3092\u9023\u7d50\u3059\u308b<\/p>\n<h5>2.1. \u30d7\u30ea\u30d7\u30ed\u30bb\u30c3\u30b5\u5c55\u958b\u524d<\/h5>\n<pre class=\"lang:c decode:true \" >#include &lt;stdio.h&gt;\r\n\r\n#define token_macro_func(x)   X##x\r\n\r\nint main() {\r\n    int   X1;\r\n    float X2;\r\n    char  Xn;\r\n\r\n    token_macro_func(1) = 10;\r\n    token_macro_func(2) = 20.0;\r\n    token_macro_func(n) = 'N';\r\n\r\n    printf(\"%d\\n\", token_macro_func(1));\r\n    printf(\"%f\\n\", token_macro_func(2));\r\n    printf(\"%c\\n\", token_macro_func(n));\r\n\r\n    return 0;\r\n}<\/pre>\n<h5>2.2. \u30d7\u30ea\u30d7\u30ed\u30bb\u30c3\u30b5\u5c55\u958b\u5f8c<\/h5>\n<pre class=\"lang:c decode:true \" >int main() {\r\n    int   X1;\r\n    float X2;\r\n    char  Xn;\r\n\r\n    X1 = 10;\r\n    X2 = 20.0;\r\n    Xn = 'N';\r\n\r\n    printf(\"%d\\n\", X1);\r\n    printf(\"%f\\n\", X2);\r\n    printf(\"%c\\n\", Xn);\r\n\r\n    return 0;\r\n}<\/pre>\n<h3>3. \u5185\u90e8\u30ea\u30f3\u30af<\/h3>\n<ul>\n<li><a href=\"\/tech\/index.php\/archives\/3962\">[C\u8a00\u8a9e] \u30d7\u30ea\u30d7\u30ed\u30bb\u30c3\u30b5 \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6<\/a><\/li>\n<\/ul>\n<h3>4. \u5916\u90e8\u30ea\u30f3\u30af<\/h3>\n<ul>\n<li>Microsoft Visual Studio <a href=\"https:\/\/docs.microsoft.com\/ja-jp\/cpp\/preprocessor\/preprocessor-operators\">\u30d7\u30ea\u30d7\u30ed\u30bb\u30c3\u30b5\u6f14\u7b97\u5b50<\/a><\/li>\n<li>Microsoft Visual Studio <a href=\"https:\/\/learn.microsoft.com\/ja-jp\/cpp\/preprocessor\/stringizing-operator-hash\">\u6587\u5b57\u5217\u5316\u6f14\u7b97\u5b50 #<\/a><\/li>\n<li>JPCERT\/CC <a href=\"https:\/\/www.jpcert.or.jp\/sc-rules\/c-pre05-c.html\">PRE05-C. \u5b57\u53e5\u306e\u7d50\u5408\u3084\u6587\u5b57\u5217\u5316\u3092\u884c\u3046\u969b\u306e\u30de\u30af\u30ed\u7f6e\u63db\u52d5\u4f5c\u3092\u3088\u304f\u7406\u89e3\u3059\u308b<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>1. \u6587\u5b57\u5217\u5316\u6f14\u7b97\u5b50 (#) \u5b9f\u5f15\u6570\u3092\u30c0\u30d6\u30eb\u30af\u30aa\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u62ec\u308b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[84,80],"class_list":["post-4233","post","type-post","status-publish","format-standard","hentry","category-memo","tag-cpp","tag-c"],"_links":{"self":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/4233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/comments?post=4233"}],"version-history":[{"count":14,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/4233\/revisions"}],"predecessor-version":[{"id":8395,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/4233\/revisions\/8395"}],"wp:attachment":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/media?parent=4233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/categories?post=4233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/tags?post=4233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}