Boost logo

Boost :

From: Lois Goldthwaite (loisg_at_[hidden])
Date: 2000-10-05 20:42:23


John,

I don't think it's legal to put the main() function in a namespace. Or
rather, it is legal, but then it's not the main() function. See clause
3.6.1 in the Standard (excerpts below):

p1: "A program shall contain a global function called main, which is the
designated start of the program. "

p2: "An implementation shall not predefine the main function. This
function shall not be overloaded. It shall have a return type of type
int, but otherwise its type is implementation-defined. All
implementations shall allow both of the following definitions of main:

    int main() { /* ... */ }

and

   int main(int argc, char* argv[]) { /* ... */ }"

p3: "The function main shall not be used within a program. The linkage
of main is implementation-defined.
A program that declares main to be inline or static is ill-formed. The
name main is not otherwise reserved. [Example: member
functions, classes, and enumerations can be called main, as can entities
in other namespaces. ]

So if you were doing this on purpose, in order to call
mynamespace::main() from somewhere else, then I guess it's a compiler
problem. Or if you're calling a complicated template function and are
getting this problem, you might try re-formatting the signature. In
VC++5 I ran into a weird bug that was dependent on white space. IIRC it
was a complicated signature, and our formatting style goes something
like this:

os_pair
      <
      os_tree_const_iterator
        <
        OS_PAIR( Key, Value ),
        OS_DIFF_TYPE( OS_PAIR( Key, Value ) )
>,
      os_tree_const_iterator
        <
        OS_PAIR( Key, Value ),
        OS_DIFF_TYPE( OS_PAIR( Key, Value ) )
>
>
    equal_range
      (
      const key_type& key
      ) const;

... or maybe one of the parameters was a map, with its four template
args similarly formatted. The fix, believe it or not, was to reformat
the code so that the '<' opening the template arg list was before the
newline character instead of after it. If I can dig out that code, I'll
try it again with VC6.

Lois

John Britton wrote:
>
> If one takes libs/graph/examples/connected_components.cpp, and
> encloses the main() function in a namespace, the VC++ compiler fails
> with the following:
>
> ...\boost\boost\graph\detail\adjacency_list.hpp(1590) : fatal error
> C1001: INTERNAL COMPILER ERROR
> (compiler file 'msc1.cpp', line 1794)
> Please choose the Technical Support command on the Visual C++
>
> While I'm sure that MS Technical Support will jump all to help me if
> I contact them, I thought I'd ask here if anyone knows what's going
> on.
>
> I'm not really just trying to compile the example, but I've lifted
> some of the code from it for my own use and ran into this problem in
> the context of my code.
>
> Thanks,
> JohnB


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