Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news.linkpendium.com!news.linkpendium.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: [OT] Can global variable be passed into Python function? Date: Sun, 2 Mar 2014 16:45:28 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 36 Message-ID: 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> NNTP-Posting-Host: c-24-118-110-103.hsd1.mn.comcast.net X-Trace: reader1.panix.com 1393778728 23194 24.118.110.103 (2 Mar 2014 16:45:28 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Sun, 2 Mar 2014 16:45:28 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) Xref: csiph.com comp.lang.python:67455 On 2014-03-02, Dave Angel wrote: > Grant Edwards Wrote in message: >> On 2014-02-24, Michael Torrie wrote: >> >>> >>> Why would you think that? The address of the start of your malloc'ed >>> structure is the same as the address of the first element. Surely >>> this is logical? >> >> Not only is it logical, the C standard explicitly requires it. Here's >> a second-hand citation since I don't happend to have an actual copy of >> the standard on hand: >> >> C1x ???6.7.2.1.13: >> >> A pointer to a structure object, suitably converted, points to >> its initial member ... and vice versa. There may be unnamed >> padding within a structure object, but not at its beginning. > > The quote you make from the C standard doesn't mention malloc, so > you're arguing different things. No, I'm not. A pointer to a structure object and a pointer to it's first field are the same. It doesn't matter where the object came from. > It's not the compiler that casts the malloc return value to the > struct type. That's irrelevent. The actual location of the memory containing the struct object (static, stack, heap, shared) doesn't matter. The address of the first field in a struture object _is_ the address of the structure object. -- Grant