Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.06; 'compiler': 0.07; 'memory.': 0.07; 'subject:into': 0.09; 'cc:addr :python-list': 0.11; '24,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:variable': 0.16; 'typedef': 0.16; 'value;': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'comparing': 0.24; 'pointer': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'locations': 0.30; 'message-id:@mail.gmail.com': 0.30; '25,': 0.31; 'struct': 0.31; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'shows': 0.36; 'subject:?': 0.36; 'itself': 0.39; 'structure': 0.39; 'subject:Can': 0.60; 'first': 0.61; 'email addr:gmail.com': 0.63; 'different': 0.65; '2014,': 0.84; 'different.': 0.84; '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=xjDTTtunx1N3d3D2Ojqnp2aIkhwY6TtlPR1aqbSAaPM=; b=mNCCC6M6rElPvj72YaGAsDN6ltwIPM/fgod1PU3wxyqME20Qz63MbArx4SPH6R/peP DdxjeVAv6yCkdnYmG6QxDUshd81cueRnKvwU62TXwZhZyvJ/xS5SrqlrM1TnxOC/dRYR g5ot2VRAtXCEuwlzbsuvHvPS6XYjrijqdlbAiofl3zw86jmz5z8IYqi4BlvRgy7kD6sh zSptXh1A9+w+elylOqukbQq8yYJymaRJ8APfG+2mOmyMPRHJ4XbNAgMFjHIExB0bwTVh dZttmK2Jh3gbnCxwMR161B9EYACQ9XF9pFW6tKkzqQanhGYydc9hXxJp3wYAi+Vxauiw R+PQ== MIME-Version: 1.0 X-Received: by 10.68.162.66 with SMTP id xy2mr1351877pbb.46.1393266325366; Mon, 24 Feb 2014 10:25:25 -0800 (PST) In-Reply-To: <1393266014.6099.87210377.38F84560@webmail.messagingengine.com> 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> <1393266014.6099.87210377.38F84560@webmail.messagingengine.com> Date: Tue, 25 Feb 2014 05:25:25 +1100 Subject: Re: 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393266334 news.xs4all.nl 2964 [2001:888:2000:d::a6]:46991 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66993 On Tue, Feb 25, 2014 at 5:20 AM, wrote: > On Mon, Feb 24, 2014, at 13:05, j.e.haque@gmail.com wrote: >> typedef struct { >> int value; >> } Number; >> >> Number *o; >> o = malloc(sizeof(*o)); >> o->value=3; >> printf("o<%p>, o->value<%p>\n", o, &o->value); >> >> o<0x9fe5008>, o->value<0x9fe5008> >> >> Is the compiler borked? > > That's cheating. Try printf("o<%p>", &o); It's not cheating, but it's showing something different. Comparing o and &o->value shows that the structure itself and its first member are at the same location in memory. Comparing o and &o shows that the structure and the pointer to the structure are at different locations in memory. ChrisA