Re: declaration vs. defintion

From: Alwyn (dt015a1979_at_mac.com.invalid)
Date: 11/01/04


Date: Mon, 01 Nov 2004 12:26:53 +0000

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 ?,

You shouldn't think of it in terms of storage being allocated. 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;

inline int timesFive(int n)
{
   return n * Five;
}

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?

> 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.

A user-defined type is not an object and is not included in the above
list.

Alwyn



Relevant Pages

  • Re: Are there any 8051 C++ compilers ?
    ... Bjarne Stroustrup wrote: ... >>would support it) remove the instance of storage if the address isn't taken. ... From this input file: ... const int seven = 7; ...
    (comp.arch.embedded)
  • Re: Const from IDL-File
    ... I have defined a "const int" in an idl file(const int ... There is no room to storage "const"s in TLB file. ...
    (microsoft.public.vc.atl)
  • Re: How to eliminate this global variable, silent?
    ... means "variable with static storage duration". ... not to the identifier of the object. ... The you provide the extern ...
    (comp.lang.c)
  • Re: How to eliminate this global variable, silent?
    ... a variable is a binding between an identifier and an area of storage. ... in the world that are not in the standard. ...
    (comp.lang.c)
  • Re: Trap representations in the absence of padding bits
    ... As an object is a named region of storage and its name is its identifier, we have come full circle haven't we? ... As for our ubiquitous "Hello, world!\n" we have an undeclared array of char said to be anonymous, known only by the address of its first character. ...
    (comp.lang.c)