{"id":2638,"date":"2018-08-11T11:10:47","date_gmt":"2018-08-11T02:10:47","guid":{"rendered":"https:\/\/www.chihayafuru.jp\/tech\/?p=2638"},"modified":"2024-11-13T09:53:47","modified_gmt":"2024-11-13T00:53:47","slug":"c-c%e6%b7%b7%e5%9c%a8%e7%92%b0%e5%a2%83%e3%81%a7%e3%83%aa%e3%83%b3%e3%82%af%e3%81%ab%e5%a4%b1%e6%95%97%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/archives\/2638","title":{"rendered":"C\/C++\u6df7\u5728\u74b0\u5883\u3067\u30ea\u30f3\u30af\u306b\u5931\u6557\u3059\u308b"},"content":{"rendered":"<p>C\/C++\u6df7\u5728\u74b0\u5883\u306b\u304a\u3044\u3066 \u300cno definition for &#8220;xxx&#8221;\u300d\u306a\u3069\u306e\u95a2\u6570\u5b9a\u7fa9\u304c\u5b58\u5728\u3057\u306a\u3044\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u30ea\u30f3\u30af\u306b\u5931\u6557\u3059\u308b\u3002<\/p>\n<h3>\u30c1\u30a7\u30c3\u30af\u30dd\u30a4\u30f3\u30c8<\/h3>\n<p>\u300e \u30de\u30f3\u30b0\u30eb (mangle) \u300f, \u300e \u540d\u524d\u30de\u30f3\u30b0\u30ea\u30f3\u30b0 (name mangling) \u300f<br \/>\n<!--more--><\/p>\n<h3>\u89e3\u6c7a\u65b9\u6cd5<\/h3>\n<p>\u89e3\u6c7a\u65b9\u6cd5\u306f\u4ee5\u4e0b\u306e (1) \uff5e (3) \u306e\u3044\u305a\u308c\u304b\u3002\u3082\u3057\u304f\u306f (1) \uff5e (3) \u306e\u7d44\u307f\u5408\u308f\u305b\u3002<\/p>\n<h4>(1) \u30d8\u30c3\u30c0\u30d5\u30a1\u30a4\u30eb\u3092 extern &quot;C&quot; \u30ea\u30f3\u30b1\u30fc\u30b8\u6307\u5b9a\u5b50\u3067\u56f2\u3080<\/h4>\n<h5>foo.h<\/h5>\n<pre class=\"lang:default decode:true \" >#ifdef\t__cplusplus\r\nextern \"C\" {\r\n#endif\t\/* __cplusplus *\/\r\n\r\n\/* \u4e2d\u7565 \uff08\u95a2\u6570\u5ba3\u8a00\uff09 *\/\r\n\r\n#ifdef\t__cplusplus\r\n}\r\n#endif\t\/* __cplusplus *\/<\/pre>\n<p>#ifdef __cplusplus \u3067\u30b9\u30a4\u30c3\u30c1\u3059\u308b\u3053\u3068\u3067\u3001C++\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb(*.cpp)\u304b\u3089\u30a4\u30f3\u30af\u30eb\u30fc\u30c9\u3055\u308c\u305f\u3068\u304d\u3060\u3051\u3001\u540d\u524d\u30de\u30f3\u30b0\u30ea\u30f3\u30b0\u304c\u6709\u52b9\u3068\u306a\u308b\u3002\uff08C, C++\u517c\u7528\u306e\u30d8\u30c3\u30c0\u30d5\u30a1\u30a4\u30eb\u3068\u306a\u308b\u3002\uff09<\/p>\n<h4>(2) C++\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u306b\u30a4\u30f3\u30af\u30eb\u30fc\u30c9\u6587\u3092\u8a18\u8ff0\u3059\u308b\u3068\u304d\u306b extern &quot;C&quot; \u30ea\u30f3\u30b1\u30fc\u30b8\u6307\u5b9a\u5b50\u3067\u56f2\u3080<\/h4>\n<h5>bar.cpp<\/h5>\n<pre class=\"lang:default decode:true \" >extern \"C\" {\r\n#include \"spam.h\"\r\n#include \"ham.h\"\r\n}<\/pre>\n<p>\u30ea\u30f3\u30b1\u30fc\u30b8\u6307\u5b9a\u306e\u8a18\u8ff0\u304c\u306a\u3044\u30d8\u30c3\u30c0\u30d5\u30a1\u30a4\u30eb\uff08\uff23\u8a00\u8a9e\u5c02\u7528\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\uff09\u3092\u3001C++\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb(*.cpp)\u304b\u3089\u30a4\u30f3\u30af\u30eb\u30fc\u30c9\u3059\u308b\u5de5\u592b\u3002<\/p>\n<h4>(3) C\u8a00\u8a9e\u95a2\u6570\u306e\u5ba3\u8a00\u306b\u4e00\u3064\u4e00\u3064\u30ea\u30f3\u30b1\u30fc\u30b8\u6307\u5b9a\u3092\u8a18\u8ff0\u3059\u308b<\/h4>\n<h5>baz.cpp<\/h5>\n<pre class=\"lang:default decode:true \" >extern \"C\" int hello(const char* name);\r\nextern \"C\" int bye(void);\r\n\r\nint Greeting::Say(void) {\r\n  \/* \u4e2d\u7565 *\/\r\n  result = hello(\"Taro\");\r\n  \/* \u4e2d\u7565 *\/\r\n}\r\n<\/pre>\n<h3>3. \u53c2\u8003\u30ea\u30f3\u30af<\/h3>\n<ul>\n<li><a href=\"https:\/\/www.ibm.com\/docs\/ja\/i\/7.3?topic=linkage-name-mangling-c-only\">[IBM] \u540d\u524d\u30de\u30f3\u30b0\u30ea\u30f3\u30b0<\/a><\/li>\n<li><a href=\"https:\/\/ja.wikipedia.org\/wiki\/%E5%90%8D%E5%89%8D%E4%BF%AE%E9%A3%BE\">[Wikipedia] \u540d\u524d\u4fee\u98fe<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>C\/C++\u6df7\u5728\u74b0\u5883\u306b\u304a\u3044\u3066 \u300cno definition for &#8220;xxx&#8221;\u300d\u306a\u3069\u306e\u95a2\u6570\u5b9a\u7fa9\u304c\u5b58\u5728\u3057\u306a\u3044\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u30ea\u30f3\u30af\u306b\u5931\u6557\u3059\u308b\u3002 \u30c1\u30a7\u30c3\u30af\u30dd\u30a4\u30f3\u30c8 \u300e \u30de\u30f3\u30b0\u30eb (mangle) \u300f,  [&hellip;]<\/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-2638","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\/2638","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=2638"}],"version-history":[{"count":10,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/2638\/revisions"}],"predecessor-version":[{"id":7512,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/2638\/revisions\/7512"}],"wp:attachment":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/media?parent=2638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/categories?post=2638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/tags?post=2638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}