Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:: [': 0.04; 'subject:Python': 0.06; 'compiler': 0.07; 'result,': 0.07; 'assumed': 0.09; 'override': 0.09; 'runtime': 0.09; 'subject:into': 0.09; 'cc:addr:python-list': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'malloc': 0.16; 'subject:variable': 0.16; 'size,': 0.16; 'wrote:': 0.18; '(not': 0.18; 'things.': 0.19; 'subject:] ': 0.20; 'cc:addr:python.org': 0.22; 'pointer': 0.24; 'space.': 0.24; 'cc:2**0': 0.24; 'mention': 0.26; 'least': 0.26; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'array': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'overhead': 0.31; 'struct': 0.31; 'beginning': 0.33; 'table': 0.34; 'convert': 0.35; 'etc': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'c++': 0.36; 'subject:?': 0.36; 'virtual': 0.37; 'two': 0.37; 'whatever': 0.38; 'pm,': 0.38; 'does': 0.39; 'quote': 0.39; 'even': 0.60; 'dave': 0.60; 'subject:Can': 0.60; 'new': 0.61; "you're": 0.61; 'address': 0.63; 'different': 0.65; 'mar': 0.68; 'angel': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=rhNGIUmG690ODv1U4zf3vlnLeh5yuBaa4lrl4/PDXsk=; b=tTUt0AwXax8s1y5JWBGW26D5+a0RrMVGR4aGIiAQRDyYKppeOxR0NOc/3LXjn+tXd7 UFELbOu5dGNcpdUlQoR589dWI4Gqy1MntSn6dgWxMghnex3yw9VerAfBazGOl02ZSw74 +L0GG8aIAUU6Ina5DE//nWOequHrxWYgx42+FDKA9WYzVkT0hNH+D9lttkCwcj1HPwVs EvebxUZzgRuGgY9bIdZ882WX70XpuPSWvEW9N2I8pJPVTDXyCW4+OjkHYwcu8O6l15tZ Ipy/KqrwzrkFrMdKxxO2pDOFZ5WtXxDmPHZhHUnh/KzYBTL9Gef2RcWBQYw7wvrbI34H vhvQ== MIME-Version: 1.0 X-Received: by 10.69.21.106 with SMTP id hj10mr12310212pbd.87.1393733842092; Sat, 01 Mar 2014 20:17:22 -0800 (PST) In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Date: Sun, 2 Mar 2014 15:17:21 +1100 Subject: Re: [OT] Can global variable be passed into Python function? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393733852 news.xs4all.nl 2893 [2001:888:2000:d::a6]:47797 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67408 On Sun, Mar 2, 2014 at 3:02 PM, Dave Angel wrote: > The quote you make from the C standard doesn't mention malloc, so > you're arguing different things. It's not the compiler that casts > the malloc return value to the struct type. > > C++ does implicitly convert the result, and the return value of > new already has the struct type. But the runtime stores at least > two kinds of overhead on occasion, the array size, and the > vtable. So the malloc address can not be assumed to match the > struct beginning. (Not even considering that one can override Whatever pointer malloc returns is the beginning of the *usable* space. Any overhead for array size etc has to be before that; a virtual function table pointer would be inside that space, but that's very much compiler-dependent. ChrisA