🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Scott Meyers Mon, 11 Mar 1996 00:39
extern inlines
#3637
Author: Scott Meyers
Date: Mon, 11 Mar 1996 00:39
35 lines
2137 bytes
I'm a little confused about the meaning of extern inline functions.
DWP 7.1.1.4 makes it clear that extern inline functions have external
linkage, so I have two questions.

1.  Suppose this definition occurs in header1.h:

      extern inline f() { cout << "Hello."; }
    
    Further suppose that header1.h is #included by file1.cpp, file2.cpp, and
    file3.cpp and that, for whatever reason, f is NOT inlined.  Which object
    file will contain the definition of f?  My understanding is that only
    one of them will.

2.  Now suppose there is a second header file header2.h, which contains
    this definition:

      extern inline f() { cout << "Goodbye."; }  // note that this is
                                                 // not the same as f above

    If I link together an object file containing the definition of f
    from header1.h and another object file containing the definition of
    f from header2.h, am I correct in assuming that the resulting
    program violates the one definition rule and that this violation
    need not be diagnosed?
    
Thanks,

Scott
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Re: extern inlines
#3639
Author: Fergus Henderson
Date: Mon, 11 Mar 1996 04:18
52 lines
2911 bytes
smeyers@netcom.com (Scott Meyers) writes:

>I'm a little confused about the meaning of extern inline functions.
>DWP 7.1.1.4 makes it clear that extern inline functions have external
>linkage, so I have two questions.
>
>1.  Suppose this definition occurs in header1.h:
>
>      extern inline f() { cout << "Hello."; }
>    
>    Further suppose that header1.h is #included by file1.cpp, file2.cpp, and
>    file3.cpp and that, for whatever reason, f is NOT inlined.  Which object
>    file will contain the definition of f?  My understanding is that only
>    one of them will.

The C++ standard does not define the notion of an "object file".
Not all implementations use object files.  (For example, C++ interpreters
may just load the source files into memory.)

However, I think typical implementations will place a definition of f()
in every object file, and then merge them at link time to ensure that
the final executable only contains one definition of f().

If you want to find out what your particular implementation does, try
compiling to assembler (often the `-S' compiler option will have this
effect) and examining the assembler file, or try exaxmining the object
file (on Unix implementations, you can use the `nm' command to do
this).

>2.  Now suppose there is a second header file header2.h, which contains
>    this definition:
>
>      extern inline f() { cout << "Goodbye."; }  // note that this is
>                                                 // not the same as f above
>
>    If I link together an object file containing the definition of f
>    from header1.h and another object file containing the definition of
>    f from header2.h, am I correct in assuming that the resulting
>    program violates the one definition rule and that this violation
>    need not be diagnosed?

Yes.

--
Fergus Henderson             	WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au              	PGP: finger fjh@128.250.37.3
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads