Re: When is a static data member defined?
From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 10/20/04
- Next message: Victor Bazarov: "Re: When is a static data member defined?"
- Previous message: Ron Natalie: "Re: When is a static data member defined?"
- In reply to: Steven T. Hatton: "Re: When is a static data member defined?"
- Next in thread: Steven T. Hatton: "Re: When is a static data member defined?"
- Reply: Steven T. Hatton: "Re: When is a static data member defined?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 20 Oct 2004 17:17:43 -0400
Steven T. Hatton wrote:
> Victor Bazarov wrote:
>
>
>>Steven T. Hatton wrote:
>>
>>
>>>Victor Bazarov wrote:
>>>
>>>
>>>
>>>>Steven T. Hatton wrote:
>>>>
>>>>
>>>>>Victor Bazarov wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>Steven T. Hatton wrote:
>>>>>>
>>>>>>
>>>>>>>So my question might be rephrased: when is the memory
>>>>>>
>>>>>>>allocation determined for the static data member?
>>>>>>
>>>>>>Memory allocation for any object is determined when the object has
>>>>>>a complete type.
>>>>>
>>>>>
>>>>>So, in the example I posted, that would be when the member declaration
>>>>>S::C s is encountered in the struct definition.
>>>>>
>>>>>Here's just something to think about:
>>>>
>>>>So, have _you_ thought about it?
>>>>
>>>>
>>>>
>>>>>#include <iostream>
>>>>>
>>>>>using std::cout;
>>>>>using std::endl;
>>>>>using std::ostream;
>>>>>
>>>>>class C {
>>>>> int _v;
>>>>>public:
>>>>>
>>>>> C(const int& v = 0)
>>>>> :_v(v)
>>>>> {}
>>>>>
>>>>> ostream& print(ostream& out) const
>>>>> {
>>>>> return out << _c._v << " " << _v;
>>>>> }
>>>>>
>>>>> static const C _c;
>>>>
>>>>That's a declaration.
>>>>
>>>>
>>>>
>>>>>};
>>>
>>>
>>>C is a complete type. So can we say C::_c is allocated at this point?
>>
>>First of all, C is not a complete type until the closing curly brace is
>>encountered.
>
>
> My eyes must be playing tricks on me.
>
>
>>Second, no, C::_c is not
>>allocated at that point. Any object is only allocated when it's _defined_
>>not when it's _declared_.
>
>
> "Memory allocation for any object is determined when the object has
> a complete type."
Determination of memory allocation (the ability to allocate memory) and
the actual _act_ of allocating memory are two different things. You need
to be a bit clearer about what you ask.
Memory is allocated when a static or automatic object is defined. For
now we can probably leave dynamic objects alone.
>
> What about this?
>
> int foo(int i) {
> int x;
> return x * i;
> }
What about it? As far as I can tell it produces undefined behaviour
because 'x' has indeterminate value.
V
- Next message: Victor Bazarov: "Re: When is a static data member defined?"
- Previous message: Ron Natalie: "Re: When is a static data member defined?"
- In reply to: Steven T. Hatton: "Re: When is a static data member defined?"
- Next in thread: Steven T. Hatton: "Re: When is a static data member defined?"
- Reply: Steven T. Hatton: "Re: When is a static data member defined?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|