Path: csiph.com!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'float': 0.05; '#include': 0.07; 'main()': 0.07; 'subject:python': 0.14; 'thu,': 0.15; '-wall': 0.16; '12:04': 0.16; '24,': 0.16; 'c++.': 0.16; 'copied,': 0.16; 'fits': 0.16; 'jmp': 0.16; 'pointers,': 0.16; 'shallow': 0.16; 'value;': 0.16; 'wrote:': 0.16; 'pointed': 0.18; 'pointer': 0.18; '2015': 0.20; 'gcc': 0.22; 'sep': 0.22; 'struct': 0.22; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'ansi': 0.29; 'cat': 0.29; "i'm": 0.30; 'foo': 0.33; 'int': 0.33; 'received:google.com': 0.35; 'something': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'to:addr:python.org': 0.40; 'within': 0.64; 'expert': 0.70; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=2IE6jzp6sQt+qeUAmOfmdHoNYO3L5O37xpc2SdHS0FQ=; b=f4cJamX4hT+KBMNK6nRjzlfJwvxamQgFPFBlHq9xKxbmbFowiGAL/i/7A0nT1SNm/s V3xpAMhWCmRWKeEscOXv8c20oT4Lu4UmVufKcVj2YODt57tYBxUWc5iYglC+kgPxt/1B jWCtPFs/wvg+rVqEx0c5aFRmcpyPEKOrO7swwlB4506mpYKSyO1OaRct9+47cyKYt54Z 046sWJWCpz8r+d3HfJHx6fNYAafUSWXBN5eSRc/hiR/sRfA+ypRyNxqP7GoqhYH1FnKq To+MoL7kRktD9BrKWT4VDrZRUxM0jweKYjeQm/HgbieBXt0acjo/6G7InTumdTEHu6dx rn7Q== X-Received: by 10.129.101.11 with SMTP id z11mr1013078ywb.85.1443118813106; Thu, 24 Sep 2015 11:20:13 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> From: Ian Kelly Date: Thu, 24 Sep 2015 12:19:33 -0600 Subject: Re: Idiosyncratic python To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1443118822 news.xs4all.nl 23820 [2001:888:2000:d::a6]:41447 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97084 On Thu, Sep 24, 2015 at 12:04 PM, jmp wrote: > I'm not an expert but I think this "return by value thing" is only for C++. > In vintage C, you can only return something that fits within a register. If that was true at one time, it was before ANSI C. $ cat test.c #include struct foo { int a; long b; float c; double d; }; struct foo get_foo() { struct foo value; value.a = 12; value.b = 92L; value.c = 4.5f; value.d = -21.5; return value; } int main() { struct foo value = get_foo(); assert(value.a == 12); assert(value.b == 92L); assert(value.c == 4.5f); assert(value.d == -21.5); return 0; } $ gcc -Wall -O0 -std=c89 test.c $ ./a.out $ There is a danger however in that it's only a shallow copy. If any struct members are pointers, then the pointer value will be copied, not the thing pointed to.