Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: x86-64 ASM output of a simple test program

Author: Dezhi Zhao

Date: 06:05:00 09/30/05

Go up one level in this thread


On September 30, 2005 at 06:41:09, David Mitchell wrote:

>On September 29, 2005 at 16:45:46, Dezhi Zhao wrote:
>>>
>>>Section 9.5, paragraph 1: "In a union, at most one of the data members can be
>>>active at any time, that is, the value of at most one of the data members can be
>>>stored in a union at any time".
>>>
>>>Thanks,
>>>Eugene
>>>
>>
>>OK. I sounds to me the standard is trying make a union thread safe by
>>definition.
>
>Consistent. Anything else would be wildly off the mark of the standards.

Hmm.... If you want to be thread safe,  Section 9.5, paragraph 1 can also apply
to any type of shared data, not just union.  However, It's programmer's job to
protect any shared data.

>
>>
>>However, does the compiler pass a structure of size 8 as in the expample by
>>value or by reference in a function call? I think it to be by reference.
>>I'm going to try it out:)
>>

>All values to a function are passed by value. Anything, such as a "reference",
>is merely a copy of the reference you used in the exiting function. In the case
>of pointers or other addresses, it just happens that those copies, have a valid
>variable (or structure, function, another address, etc.), that is valid.
>
>Dave

I understand those definitions well.  And Eugene knew what I was talking about.
But here is what I wanted to check with the compiler anyways:

struct (or union) struct_of_size_8
{
   .....
   .....
} s;

void foo(struct_of_size_8);

The question is if s is passed by value or by reference in a call to foo:
foo(s);

The above question cannot be simply answered by c/c++ textbook definitions if we
are talking about a highly optimized compiler.

I did some tests with the compiler. The compiler does pass the parameter by
value for some simple 8 byte structures, treating s as an int64. I'm going to
test more. The compiler does a good job in parsing function parameters anyways.







This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.