{"id":357,"date":"2010-08-23T15:49:00","date_gmt":"2010-08-23T07:49:00","guid":{"rendered":"http:\/\/localhost\/?p=357"},"modified":"2010-08-23T15:49:00","modified_gmt":"2010-08-23T07:49:00","slug":"c___how_to_implement_the_function_for_any_length_parameter_","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/wjmzbmr\/?p=357","title":{"rendered":"C++\u4e2d\u5982\u4f55\u5b9e\u73b0\u51fd\u6570\u4efb\u610f\u957f\u53c2\u6570\u3002\u3002\u3002"},"content":{"rendered":"<p> \u989d\u3002\u3002\u8fd9\u662f\u4e00\u7bc7\u6709\u70b9\u65e0\u804a+SB\u7684\u6587\u7ae0\u3002\u3002\u795e\u725b\u53ef\u4ee5\u65e0\u89c6\u56e7\u3002\u3002\u3002<br \/>\u6069\u3002\u3002\u6bd4\u5982\u8bf4\u4f60\u5728Dp\u6216\u8005XX\u7684\u65f6\u5019\u3002\u3002\u9700\u8981\u4e00\u4e9b\u4e2a\u6570\u7684\u6700\u5927\u503c\uff0c<br \/>\u624b\u52a8\u6bd4\u8f83\u548c\u7528max\u90fd\u5f88\u9ebb\u70e6\u7684\u8bdd\u3002\u3002\u53ef\u4ee5\u8003\u8651\u7528\u8fd9\u4e2a\u53ef\u53d8\u957f\u5f62\u53c2\u3002\u3002<br \/>inline int max(int n,&#8230;)<br \/>{<br \/>    va_list ap;<br \/>    va_start(ap,n);<br \/>    int ret=-inf,i,x;<br \/>    rep(i,n){x=va_arg(ap,int);if(x&gt;ret)ret=x;}<br \/>    va_end(ap);<br \/>    return ret;<br \/>}<br \/>\u7136\u540e\u5c31\u53ef\u4ee5\u8fd9\u4e48\u8c03\u7528\u4e86\u3002\u3002<br \/>max(3,1,9,8);\u770b\u4e0a\u53bb\u8fdc\u6ca1\u6709Java\u7684\u723d\u56e7\u3002\u3002\u4e0d\u8fc7\u51d1\u5408\u51d1\u5408\u5427\u3002\u3002<br \/>va_list\u662f\u4e00\u4e2a\u9884\u5148\u5b9a\u4e49\u7684\u6570\u636e\u7ed3\u6784\uff0c\u7528\u6765\u50a8\u5b58\u53c2\u6570\u5217\u8868\u7684\u3002<br \/>va_start\u5c31\u662f\u628a\u53c2\u6570\u653e\u5230va_list\u91cc\u9762\u53bb\uff0c\u540e\u9762\u8fd8\u8981\u8ddf\u4e2an\u8868\u793a\u53c2\u6570\u7684\u4e2a\u6570\u3002\u3002<br \/>va_arg(ap,int)\u6bcf\u6b21\u53d6\u51fa\u4e0b\u4e00\u4e2a\u53c2\u6570\uff0c\u8fd8\u8981\u6307\u5b9a\u7c7b\u578b\u3002\u3002<br \/>\u6700\u540e\u4e00\u4e2ava_end(ap)\u8868\u793a\u6e05\u7a7a\u8fd9\u4e2a\uff0c\u56de\u6536\u5185\u5b58\u3002\u3002\u3002<\/p>\n<p>\u8fd8\u6709\u5728#define\u91cc\u9762\u4e5f\u6709\u8fd9\u6837\u7684\u7528\u6cd5\u7c7b\u4f3c\u7684\u3002\u3002<br \/>#define rep(i,n) for(i=0;i&lt;n;i++)<br \/>#define SC(&#8230;) scanf(__VA_ARGS__)<br \/>#define PR(&#8230;) printf(__VA_ARGS__)<br \/>int main()<br \/>{<br \/>    int x;<br \/>    SC(&quot;%d&quot;,&amp;x);<br \/>    PR(&quot;%d&quot;,x);<br \/>} <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u989d\u3002\u3002\u8fd9\u662f\u4e00\u7bc7\u6709\u70b9\u65e0\u804a+SB\u7684\u6587\u7ae0\u3002\u3002\u795e\u725b\u53ef\u4ee5\u65e0\u89c6\u56e7\u3002\u3002\u3002\u6069\u3002\u3002\u6bd4\u5982\u8bf4\u4f60\u5728Dp\u6216\u8005XX\u7684\u65f6\u5019\u3002\u3002\u9700\u8981\u4e00\u4e9b\u4e2a\u6570\u7684\u6700\u5927\u503c\uff0c\u624b\u52a8\u6bd4\u8f83\u548c\u7528max\u90fd\u5f88\u9ebb\u70e6\u7684\u8bdd\u3002\u3002\u53ef\u4ee5\u8003\u8651\u7528\u8fd9\u4e2a\u53ef\u53d8\u957f\u5f62\u53c2\u3002\u3002inline int max(int n,&#8230;){ va_list ap; va_start(ap,n); int ret=-inf,i,x; rep(i,n){x=va_arg(ap,int);if(x&gt;ret)ret=x;} va_end(ap); return ret;}\u7136\u540e\u5c31\u53ef\u4ee5\u8fd9\u4e48\u8c03\u7528\u4e86\u3002\u3002max(3,1,9,8);\u770b\u4e0a\u53bb\u8fdc\u6ca1\u6709Java\u7684\u723d\u56e7\u3002\u3002\u4e0d\u8fc7\u51d1\u5408\u51d1\u5408\u5427\u3002\u3002va_list\u662f\u4e00\u4e2a\u9884\u5148\u5b9a\u4e49\u7684\u6570\u636e\u7ed3\u6784\uff0c\u7528\u6765\u50a8\u5b58\u53c2\u6570\u5217\u8868\u7684\u3002va_start\u5c31\u662f\u628a\u53c2\u6570\u653e\u5230va_list\u91cc\u9762\u53bb\uff0c\u540e\u9762\u8fd8\u8981\u8ddf\u4e2an\u8868\u793a\u53c2\u6570\u7684\u4e2a\u6570\u3002\u3002va_arg(ap,int)\u6bcf\u6b21\u53d6\u51fa\u4e0b\u4e00\u4e2a\u53c2\u6570\uff0c\u8fd8\u8981\u6307\u5b9a\u7c7b\u578b\u3002\u3002\u6700\u540e\u4e00\u4e2ava_end(ap)\u8868\u793a\u6e05\u7a7a\u8fd9\u4e2a\uff0c\u56de\u6536\u5185\u5b58\u3002\u3002\u3002 \u8fd8\u6709\u5728#define\u91cc\u9762\u4e5f\u6709\u8fd9\u6837\u7684\u7528\u6cd5\u7c7b\u4f3c\u7684\u3002\u3002#define rep(i,n) for(i=0;i&lt;n;i++)#define SC(&#8230;) scanf(__VA_ARGS__)#define PR(&#8230;) printf(__VA_ARGS__)int main(){ int x; SC(&quot;%d&quot;,&amp;x); PR(&quot;%d&quot;,x);}<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/357"}],"collection":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=357"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}