Boost logo

Boost :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2001-06-13 20:55:06


At 04:47 PM 6/13/2001, Darin Adler wrote:
>On Wednesday, June 13, 2001, at 07:47 AM, Beman Dawes wrote:
>
>>> 5) In test_main.cpp I made report_error() and report_critical_error()
>>> static.
>>
>> Uh, run that one by me again. What does making a function static
inside
>> a
>> namespace do, anyhow?
>
>Marking a function static makes it have internal linkage. This is a
>separate issue from whether the function is in a namespace or not. It's
>true that there's no need for internal linkage for things that are inside

>an anonymous namespace, but for things that are in a non-anonymous
>namespace it still makes sense to either nest an anonymous namespace or
>use static to hide the function.

That's what I thought. But what is confusing about the request is that the
two functions in question are declared in a header (test_tools.hpp) so they
shouldn't be hidden.

> The idea is to make certain that there
>are no references to the function in other files. If there were
references
>in other files, you'd want to have a header with the declaration in it,
so
>all the files share the same declaration.
>
>Metrowerks CodeWarrior has a nice warning that warns about functions that

>are defined without a previous declaration. This is to help you remember
>to put declarations into header files. To avoid these warnings every
>function definition must either:
>
> 1) Have a separate declaration before the definition, or
> 2) be inside an anonymous namespace, or
> 3) have internal linkage, or
> 4) be marked inline.
>
>Case 1 is typical for header files, 2 is the modern way of hiding things
>that are private to a single file, 3 is the old-fashioned C way of hiding

>things that are private to a single file, and 4 there because it's normal

>to have external linkage inlines in header files without separate
>declarations. (Don't get me started on internal vs. external linkage
>inlines unless you are really interested.)
>
>An appropriate fix for test_main.cpp is to put report_error and
>report_critical_error into an anonymous namespace nested inside namespace

>boost.
>
>A side note: I'd like to see the cpp_main function's declaration in a
>cpp_main.hpp header and the test_main function's declaration in a
>test_main.hpp header.

Ullrich Koethe and I have been working on getting his unit test library
ready for review. That will involve a lot of internal implementation
changes to the Boost Test Library, so I'm planning to ask for a formal
review of the whole package. That would be the time to make those
changes. I'll add 'em to the to-do list.

--Beman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk