Re: declaration vs. defintion
From: Alwyn (dt015a1979_at_mac.com.invalid)
Date: 11/01/04
- Next message: Alwyn: "Re: Question about std::remove"
- Previous message: Chris \( Val \): "Re: Question about std::remove"
- In reply to: Chris \( Val \): "Re: declaration vs. defintion"
- Next in thread: AngleWyrm: "Re: declaration vs. defintion"
- Reply: AngleWyrm: "Re: declaration vs. defintion"
- Reply: Chris \( Val \): "Re: declaration vs. defintion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 01 Nov 2004 13:06:03 +0000
In article <2umpgfF2astf0U1@uni-berlin.de>, Val \
<chrisval@bigpond.com.au> wrote:
> "Alwyn" <dt015a1979@mac.com.invalid> wrote in message
> news:011120041226534152%dt015a1979@mac.com.invalid...
> | In article <2ummi2F2bqr3qU1@uni-berlin.de>, Val \
> | <chrisval@bigpond.com.au> wrote:
> | >
> | > AFAIU, when we say we have *defined* something, doesn't
> | > that imply that storage is associated with the particular
> | > identifier being defined ?,
>
> Hi Alwyn.
>
> | You shouldn't think of it in terms of storage being allocated.
>
> You're probably right, but it's difficult not to.
> Let me try to explain further.
>
> | Just think of a definition as a specification that is
> | sufficiently complete to be used in a program.
> |
> | Take for instance:
> |
> | const int Five = 5;
>
> The above is a definition, yes, I agree.
>
> | inline int timesFive(int n)
> | {
> | return n * Five;
> | }
>
> This function is also a definition.
>
> | There is no need for there to be storage associated with either Five or
> | timesFive, yet they have been defined, and they are usable, no?
>
> But in your example, they *do* have storage accossiated
> with them.
No, they don't necessarily. They just stand there for the compiler to
use as it thinks fit. If you take the address of either, then it will
be compelled to allocate space, otherwise there is no good reason for
it.
> This...
> int Five;
>
> ...alone is a definition of an integer variable with the
> identifier names 'Five', and has automatic storage.
Well, it could be global too. Without seeing the context, you cannot
tell whether it is automatic or global/static.
> | > therefore meaning that once we
> | > have a definition of an object, we cannot define it again ?,
> | > hence the ODR ?
> |
> | I believe the one-definition rule goes something like this:
> |
> | A translation unit must not contain more than one definition of any
> | variable, function, class type, enumeration type, or template, and
> | external definitions must not be redefined within a program.
>
> Ok, so how do you see that contradicting this:
>
> int main()
> {
> typedef int Int;
> typedef int Int;
> typedef int Int;
>
> std::cout << Int( 100 ) << std::endl;
>
> return 0;
> }
>
> ?
It doesn't. Typedefs are a special case. You can (re)define them as
many times as you like.
> | A user-defined type is not an object and is not included in
> | the above list.
>
> Right, because it is only the blueprint of the object to be
> instantiated from it.
Yes, though my wording was a little imprecise. Classes and enumerations
could be called user-defined types, and templates could also be
considered 'blueprints', yet they are in the list of things that cannot
be redefined. I was specifically thinking of 'typedef's there, which
are nothing more than a name for an existing type.
Hoping I haven't made things even more confusing for you. :-)
Alwyn
- Next message: Alwyn: "Re: Question about std::remove"
- Previous message: Chris \( Val \): "Re: Question about std::remove"
- In reply to: Chris \( Val \): "Re: declaration vs. defintion"
- Next in thread: AngleWyrm: "Re: declaration vs. defintion"
- Reply: AngleWyrm: "Re: declaration vs. defintion"
- Reply: Chris \( Val \): "Re: declaration vs. defintion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|