{"id":3612,"date":"2012-07-15T16:29:22","date_gmt":"2012-07-15T07:29:22","guid":{"rendered":"http:\/\/nanoappli.com\/blog\/?p=3612"},"modified":"2012-07-15T16:29:22","modified_gmt":"2012-07-15T07:29:22","slug":"c%e8%a8%80%e8%aa%9eswitch%e6%96%87%e3%81%aecase%e5%8f%a5%e3%81%ae%e5%be%8c%e3%81%ab%e3%82%b9%e3%83%9a%e3%83%bc%e3%82%b9%e3%81%8c%e5%bf%85%e8%a6%81%e3%81%aa%e5%a0%b4%e5%90%88%e4%b8%8d%e8%a6%81","status":"publish","type":"post","link":"http:\/\/nanoappli.com\/blog\/archives\/3612","title":{"rendered":"[C\u8a00\u8a9e]switch\u6587\u306ecase\u53e5\u306e\u5f8c\u306b\u30b9\u30da\u30fc\u30b9\u304c\u5fc5\u8981\u306a\u5834\u5408\/\u4e0d\u8981\u306a\u5834\u5408"},"content":{"rendered":"<p>\n\u4eba\u304c\u66f8\u3044\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u898b\u3066\u3044\u305f\u3068\u304d\u3001switch\u6587\u306ecase\u53e5\u306e\u66f8\u304d\u65b9\u306b\u9055\u548c\u611f\u304c\u3042\u308b\u30b3\u30fc\u30c9\u304c\u6709\u308a\u307e\u3057\u305f\u3002<br \/>\n\u8981\u70b9\u3060\u3051\u629c\u7c8b\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u5185\u5bb9\u3067\u3059\u3002<br \/>\n<pre lang=\"c\">\n    switch( data ) {\n            ...\n        case'1':    \/\/ <- case\u3068'1'\u306e\u9593\u306b\u7a7a\u767d\u304c\u306a\u3044!!\n            ...\n            break;\n        case'2':\n            ...\n            break;\n        default:\n            ...\n            break;\n    }\n<\/pre>\ncase\u3068\u6761\u4ef6\u5024\u306e\u9593\u306b\u306f\u30b9\u30da\u30fc\u30b9\u304c\u5fc5\u8981\u3060\u3068\u601d\u3063\u3066\u305f\u306e\u3067\u3059\u304c\u3001\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u306f\u3069\u3046\u3084\u3089\u30b3\u30f3\u30d1\u30a4\u30eb\u3082\u6b63\u5e38\u306b\u884c\u3048\u3001\u632f\u308b\u821e\u3044\u3082\u60f3\u5b9a\u3069\u304a\u308a\u306a\u69d8\u3067\u3059\u3002<br \/>\n<br \/>\n<br \/>\n\u6c17\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u3053\u306e\u3078\u3093\u306e\u632f\u308b\u821e\u3044\u306b\u95a2\u3059\u308b\u78ba\u8a8d\u7528\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n<pre lang=\"c\">\n#include <stdio.h>\n#define CS4 '4'\n\nint main()\n{\n    int data;\n\n    printf( \"please input data>\" );\n    scanf( \"%d\", &data );\n\n    switch( data ) {\n        case 0:\n            printf( \"pos0\\n\" );\n            break;\n        case1:      \/\/ \u7a7a\u767d\u3092\u5165\u308c\u306a\u3044\n            printf( \"pos1\\n\" );\n            break;\n        case '2':   \/\/ '2' = 0x32 = 50\n            printf( \"pos2\\n\" );\n            break;\n        case'3':    \/\/ '3' = 0x33 = 51\n            printf( \"pos3\\n\" );\n            break;\n        caseCS4:    \/\/ define\u5024\u3067\u7a7a\u767d\u3092\u5165\u308c\u306a\u3044\n            printf( \"pos4\\n\" );\n            break;\n        case0x05:   \/\/ 16\u9032\u6570\u3067\u7a7a\u767d\u3092\u5165\u308c\u306a\u3044\n            printf( \"pos5\\n\" );\n            break;\n        default:\n            printf( \"default\\n\" );\n            break;\n    }\n}\n<\/pre>\n<br \/>\n\u5b9f\u884c\u7d50\u679c:<br \/>\n<pre lang=\"x\">\n$ gcc switch_test.c  -o switch_test\n\n$ .\/switch_test \nplease input data>0\npos0\n\n$ .\/switch_test \nplease input data>1\ndefault\n\n$ .\/switch_test \nplease input data>50\npos2\n\n$ .\/switch_test \nplease input data>51\npos3\n\n$ .\/switch_test \nplease input data>52 \ndefault\n\n$ .\/switch_test \nplease input data>5\ndefault\n<\/pre>\n<br \/>\n<br \/>\n\u5404\u30d1\u30bf\u30fc\u30f3\u306e\u52d5\u4f5c\u7d50\u679c\u306b\u5bfe\u3057\u3066\u3001\u306a\u305c\u305d\u3046\u306a\u3063\u305f\u306e\u304b\u3092\u8003\u3048\u3066\u898b\u307e\u3059<br \/>\n<pre lang=\"x\">\ncase 0\n    \u3053\u308c\u306f\u6b63\u5e38\u30d1\u30bf\u30fc\u30f3\u306a\u306e\u3067\u3001\u5f53\u7136\u52d5\u4f5c\u3057\u307e\u3059\u3002\n\ncase1:\n    \"case1\"\u3068\u3044\u3046goto\u30e9\u30d9\u30eb\u3068\u89e3\u91c8\u3055\u308c\u308b\u306e\u3067\u3001\u6b63\u3057\u304f\u52d5\u4f5c\u3057\u307e\u305b\u3093\u3002\n    \u5f8c\u8ff0\u3057\u307e\u3059\u304c\u3001\u30a2\u30bb\u30f3\u30d6\u30e9\u306e\u7d50\u679c\u3092\u898b\u3066\u3082\"pos1\"\u306e\u51fa\u529b\u51e6\u7406\u81ea\u4f53\u304c\u7701\u304b\u308c\u3066\u3044\u307e\u3059\u3002\n\ncase '2':\n    \u3053\u308c\u3082\u6b63\u5e38\u30d1\u30bf\u30fc\u30f3\u3002\u52d5\u4f5c\u3057\u307e\u3059\u3002\n\ncase'3':\n    \u3053\u308c\u304c\u5f53\u521d\u9055\u548c\u611f\u3092\u611f\u3058\u305f\u30d1\u30bf\u30fc\u30f3\u3067\u3059\u3002\n    gcc\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u307e\u3057\u305f\u304c\u3001\u306f\u3084\u308a\u6b63\u5e38\u306b\u52d5\u4f5c\u3057\u3066\u307e\u3059\u3002\n\ncaseCS4:\n    \u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u305f\u3068\u304d\u306f\u3001\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u306f\u3044\u3051\u308b\u306e\u3067\u306f...\u3068\u601d\u3063\u3066\u305f\u306e\u3067\u3059\u304c\u3001NG\u3067\u3057\u305f\u3002\n    \u826f\u304f\u8003\u3048\u3066\u307f\u305f\u3089\u3001\"caseCS4\"\u3068\u3044\u3046goto\u30e9\u30d9\u30eb\u3068\u8a8d\u8b58\u3055\u308c\u308b\u3060\u3051\u306a\u306e\u3067\u3001\u30c0\u30e1\u3067\u5f53\u7136\u3067\u3059\u306d\u3002\n\ncase0x05:\n    \u3053\u308c\u3082\u30c0\u30e1\u3067\u3057\u305f\u3002\n<\/pre>\n<br \/>\n<br \/>\n\u3067\u3001\u3053\u3061\u3089\u304c\u30a2\u30bb\u30f3\u30d6\u30eb\u51fa\u529b\u3067\u3059\u3002<br \/>\npos1, pos4, pos5\u306b\u95a2\u3057\u3066\u306f\u3001\u51e6\u7406\u81ea\u4f53\u304c\u7121\u304b\u3063\u305f\u3082\u306e\u3068\u898b\u306a\u3055\u308c\u3066\u307e\u3059(\u30b3\u30fc\u30c9\u307e\u3067\u8ffd\u308f\u306a\u304f\u3066\u3082.LCx\u306e\u5b9a\u6570\u90e8\u3060\u3051\u898b\u308c\u3070\u4e00\u76ee\u77ad\u7136\u3067\u3059)\u3002<br \/>\n\u30b8\u30e3\u30f3\u30d7\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u306a\u3044goto\u30e9\u30d9\u30eb\u3068\u898b\u306a\u3055\u308c\u305f\u304b\u3089\u3060\u3068\u601d\u308f\u308c\u307e\u3059\u3002<br \/>\n<pre lang=\"x\">\n$ gcc switch_test.c  -S\n\n\n$ cat switch_test.s\n    .file   \"switch_test.c\"\n    .section    .rodata\n.LC0:\n    .string \"please input data>\"\n.LC1:\n    .string \"%d\"\n.LC2:\n    .string \"pos0\"\n.LC3:\n    .string \"pos2\"\n.LC4:\n    .string \"pos3\"\n.LC5:\n    .string \"default\"\n    .text\n    .globl  main\n    .type   main, @function\nmain:\n.LFB0:\n    .cfi_startproc\n    pushl   %ebp\n    .cfi_def_cfa_offset 8\n    .cfi_offset 5, -8\n    movl    %esp, %ebp\n    .cfi_def_cfa_register 5\n    andl    $-16, %esp\n    subl    $32, %esp\n    movl    $.LC0, %eax\n    movl    %eax, (%esp)\n    call    printf\n    movl    $.LC1, %eax\n    leal    28(%esp), %edx\n    movl    %edx, 4(%esp)\n    movl    %eax, (%esp)\n    call    __isoc99_scanf\n    movl    28(%esp), %eax\n    cmpl    $50, %eax\n    je  .L4\n    cmpl    $51, %eax\n    je  .L5\n    testl   %eax, %eax\n    jne .L7\n.L3:\n    movl    $.LC2, (%esp)\n    call    puts\n    jmp .L8\n.L4:\n    movl    $.LC3, (%esp)\n    call    puts\n    jmp .L8\n.L5:\n    movl    $.LC4, (%esp)\n    call    puts\n    jmp .L8\n.L7:\n    movl    $.LC5, (%esp)\n    call    puts\n    nop\n.L8:\n    leave\n    .cfi_restore 5\n    .cfi_def_cfa 4, 4\n    ret\n    .cfi_endproc\n.LFE0:\n    .size   main, .-main\n    .ident  \"GCC: (Ubuntu\/Linaro 4.6.1-9ubuntu3) 4.6.1\"\n    .section    .note.GNU-stack,\"\",@progbits\n<\/pre>\n<br \/>\n<br \/>\n\u3068\u3044\u3046\u308f\u3051\u3067\u3001\u76f4\u611f\u306b\u53cd\u3059\u308b\u632f\u308b\u821e\u3044\u306f\"case\u306e\u5f8c\u306b\u7a7a\u767d\u3092\u304a\u304b\u305a\u306b\u6587\u5b57\u5b9a\u6570\u304c\u7d9a\u304f\"\u30d1\u30bf\u30fc\u30f3\u3060\u3051\u3067\u3057\u305f\u3002<br \/>\n\u3053\u306e\u632f\u308b\u821e\u3044\u306b\u306a\u308b\u539f\u56e0\u3092JIS X3010\u306e\u898f\u683c\u66f8\u304b\u3089\u8abf\u3079\u3066\u307f\u305f\u306e\u3067\u3059\u304c\u3001\u5206\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f...<br \/>\n\u306a\u305c\u3060\u308d\u3046??<br \/>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eba\u304c\u66f8\u3044\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u898b\u3066\u3044\u305f\u3068\u304d\u3001switch\u6587\u306ecase\u53e5\u306e\u66f8\u304d\u65b9\u306b\u9055\u548c\u611f\u304c\u3042\u308b\u30b3\u30fc\u30c9\u304c\u6709\u308a\u307e\u3057\u305f\u3002 \u8981\u70b9\u3060\u3051\u629c\u7c8b\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u5185\u5bb9\u3067\u3059\u3002 switch( data ) { &#8230; case&#8217;1&#8242;: \/\/ 0 pos0 $ .\/switch_test please input data>1 default $ .\/switch_test please input data>50 pos2 $ .\/switch_test please input data>51 pos3 $ .\/switch_test please input data>52 default $ .\/switch_test\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[88],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":6030,"url":"http:\/\/nanoappli.com\/blog\/archives\/6030","url_meta":{"origin":3612,"position":0},"title":"[C#]switch\u6587\u306ecase\u53e5\u306e\u4e2d\u3060\u3051\u3067\u6709\u52b9\u306a\u5909\u6570\u3092\u5ba3\u8a00\u3059\u308b[C,C++,java\u3082\u540c\u69d8]","date":"2012\u5e7412\u67085\u65e5","format":false,"excerpt":"\u30d7\u30ed\u30b0\u30e9\u30e0\u4e2d\u306b\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u69d8\u306aswitch\u6587\u304c\u3042\u3063\u305f\u3068\u3057\u307e\u3059\u3002 void func( int in\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3595,"url":"http:\/\/nanoappli.com\/blog\/archives\/3595","url_meta":{"origin":3612,"position":1},"title":"[C\u8a00\u8a9e\u5165\u9580]\u8907\u6570\u306e\u5206\u5c90\u3092switch\u3067\u30b7\u30f3\u30d7\u30eb\u306b\u8a18\u8ff0\u3059\u308b","date":"2012\u5e747\u670813\u65e5","format":false,"excerpt":"\u524d\u56de\u3001if\u6587\u306b\u3088\u308b\u51e6\u7406\u306e\u5206\u5c90\u3092\u8aac\u660e\u3057\u307e\u3057\u305f\u3002 C\u8a00\u8a9e\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306fif\u3055\u3048\u3042\u308c\u3070\u3042\u3089\u3086\u308b\u5206\u5c90\u306f\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5002,"url":"http:\/\/nanoappli.com\/blog\/archives\/5002","url_meta":{"origin":3612,"position":2},"title":"[C\u8a00\u8a9e\u57fa\u790e]switch\u6587\u3067\u5076\u6570\u30fb\u5947\u6570\u306e\u5224\u5b9a\u3092\u884c\u3046\u65b9\u6cd5","date":"2012\u5e7410\u670812\u65e5","format":false,"excerpt":"int\u578b\u306e\u5909\u6570\u306b\u5165\u3063\u3066\u3044\u308b\u5024\u3092switch\u6587\u3067\u5076\u5947\u5224\u5b9a\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002 int a = ...;\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3562,"url":"http:\/\/nanoappli.com\/blog\/archives\/3562","url_meta":{"origin":3612,"position":3},"title":"[C\u8a00\u8a9e\u5165\u9580]\u51e6\u7406\u306e\u5185\u5bb9\u3092if\u6587\u3067\u5206\u5c90\u3055\u305b\u308b","date":"2012\u5e747\u670812\u65e5","format":false,"excerpt":"\u524d\u56de\u307e\u3067\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u78ba\u8a8d\u3057\u305f\u3088\u3046\u306b\u3001C\u8a00\u8a9e\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u57fa\u672c\u7684\u306b\u4e0a\u304b\u3089\u66f8\u3044\u305f\u9806\u306b\u95a2\u6570\u304c\u5b9f\u884c\u3055\u308c\u3066\u3044\u304f\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4461,"url":"http:\/\/nanoappli.com\/blog\/archives\/4461","url_meta":{"origin":3612,"position":4},"title":"[HEW]\u30b3\u30f3\u30d1\u30a4\u30eb\u6642,gcc -Wall\u306e\u3088\u3046\u306b\u5168\u3066\u306e\u8b66\u544a\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\u3055\u305b\u308b\u65b9\u6cd5","date":"2012\u5e749\u670812\u65e5","format":false,"excerpt":"H8\u306e\u7d71\u5408\u958b\u767a\u74b0\u5883\u3067\u3042\u308bHEW\u306e\u8a71\u3067\u3059\u3002 C\u8a00\u8a9e\u306e\u30b3\u30f3\u30d1\u30a4\u30e9\u3068\u3057\u3066\u3001\u4f8b\u3048\u3070gcc\u3092\u6307\u5b9a\u3059\u308b\u5834\u5408\u3060\u3068-\u2026","rel":"","context":"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/09\/20120912_05-500x347.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":5253,"url":"http:\/\/nanoappli.com\/blog\/archives\/5253","url_meta":{"origin":3612,"position":5},"title":"[C#]lock\u6587\u3067\u6392\u4ed6\u3092\u3068\u308b\u4ed5\u7d44\u307f\u304cC#4.0\u3067\u5909\u66f4\u3055\u308c\u305f\u4ef6","date":"2012\u5e7410\u670827\u65e5","format":false,"excerpt":"C#\u3067\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u6392\u4ed6\u3092\u53d6\u308b\u305f\u3081\u306block\u6587\u304c\u3042\u308a\u307e\u3059\u3002 lock( obj ) { body\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/3612"}],"collection":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/comments?post=3612"}],"version-history":[{"count":5,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/3612\/revisions"}],"predecessor-version":[{"id":3617,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/3612\/revisions\/3617"}],"wp:attachment":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/media?parent=3612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/categories?post=3612"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/tags?post=3612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}