Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97084

Re: Idiosyncratic python

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 <ian.g.kelly@gmail.com>
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 <mu1dv1$hrk$1@ger.gmane.org>
References <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <mu0eq4$2d2$1@ger.gmane.org> <CAJ4+4aoDY30HmhNrOjG2g+ODoS1vSOMtuANXp0unbuwWcuQd3g@mail.gmail.com> <mu102h$2oh$1@ger.gmane.org> <CALwzidk73ZnivKH8ajB0yFzBDc_s5mtvE283tjYjgRE2T2Px=Q@mail.gmail.com> <mu1dv1$hrk$1@ger.gmane.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 24 Sep 2015 12:19:33 -0600
Subject Re: Idiosyncratic python
To Python <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.138.1443118822.28679.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Thu, Sep 24, 2015 at 12:04 PM, jmp <jeanmichel@sequans.com> 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 <assert.h>

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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Idiosyncratic python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-09-24 16:02 +1000
  Re: Idiosyncratic python Paul Rubin <no.email@nospam.invalid> - 2015-09-23 23:16 -0700
    Re: Idiosyncratic python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-09-24 16:35 +1000
      Re: Idiosyncratic python Ben Finney <ben+python@benfinney.id.au> - 2015-09-24 16:54 +1000
        Re: Idiosyncratic python Steven D'Aprano <steve@pearwood.info> - 2015-09-25 11:08 +1000
      Re: Idiosyncratic python Terry Reedy <tjreedy@udel.edu> - 2015-09-24 02:54 -0400
  Re: Idiosyncratic python wxjmfauth@gmail.com - 2015-09-24 00:06 -0700
    Re: Idiosyncratic python Laurent Pointal <laurent.pointal@free.fr> - 2015-09-24 19:50 +0200
      Re: Idiosyncratic python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-24 21:05 +0100
  Re: Idiosyncratic python jmp <jeanmichel@sequans.com> - 2015-09-24 11:12 +0200
  Re: Idiosyncratic python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-24 14:09 +0100
  Re: Idiosyncratic python jmp <jeanmichel@sequans.com> - 2015-09-24 16:07 +0200
  Re: Idiosyncratic python Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-24 08:26 -0600
  Re: Idiosyncratic python Chris Angelico <rosuav@gmail.com> - 2015-09-25 02:57 +1000
  Re: Idiosyncratic python jmp <jeanmichel@sequans.com> - 2015-09-24 20:04 +0200
  Re: Idiosyncratic python Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-24 12:19 -0600
  Re: Idiosyncratic python Ned Batchelder <ned@nedbatchelder.com> - 2015-09-24 13:46 -0700
    Re: Idiosyncratic python Laura Creighton <lac@openend.se> - 2015-09-24 23:08 +0200
    Re: Idiosyncratic python Chris Angelico <rosuav@gmail.com> - 2015-09-25 07:49 +1000
    Re: Idiosyncratic python Steven D'Aprano <steve@pearwood.info> - 2015-09-25 10:55 +1000
  Re: Idiosyncratic python sohcahtoa82@gmail.com - 2015-09-24 15:32 -0700
  Re: Idiosyncratic python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-25 00:40 +0100
  Re: Idiosyncratic python Akira Li <4kir4.1i@gmail.com> - 2015-09-25 03:04 +0300
  Re: Idiosyncratic python Steven D'Aprano <steve@pearwood.info> - 2015-09-25 10:08 +1000

csiph-web