bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

some const tables ending up in data segment


From: James Kanze
Subject: some const tables ending up in data segment
Date: Mon, 11 Feb 2008 07:49:26 -0800 (PST)
User-agent: G2/1.0

I'm not sure that this is a bug (although it sort of looks like
one), but given the following program:

    #include <stddef.h>

    template< typename T >
    struct Table
    {
        struct DataNode ;
        struct PtrNode ;

        struct Pointer
        {
            void*               ptr ;
            DataNode*           data() const
                {   return static_cast< DataNode* >( ptr ) ; }
            PtrNode*            ptrs() const
                {   return static_cast< PtrNode* >( ptr ) ; }
        } ;

        struct DataNode
        {
            T                   data[ 16 ] ;
        } ;

        struct PtrNode
        {
            Pointer             data[ 16 ] ;
        } ;

        template< typename FwdIter >
        T                   get( FwdIter begin, FwdIter end ) const ;

        PtrNode*            highData ;
    } ;

    ::Table< int >::DataNode const d1 =
    {{
         0,  1,  2,  3,  4,  5,  6,  7,
         8,  9, -1, -1, -1, -1, -1, -1,
    }} ;

    ::Table< int >::PtrNode const p1 =
    {{
        NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
        NULL, NULL, NULL, NULL, NULL, NULL, NULL, (void*)( &d1 ),
    }} ;

    ::Table< int >::DataNode const d2 =
    {{
         0,  1,  2,  3,  4,  5,  6,  7,
         8,  9, -1, -1, -1, -1, -1, -1,
    }} ;

    ::Table< int >::PtrNode const p2 =
    {{
        NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
        NULL, NULL, NULL, NULL, NULL, NULL, NULL, (void*)( &d2 ),
    }} ;

    ::Table< int >::PtrNode const p3 =
    {{
        NULL, NULL, NULL, NULL, NULL, NULL, NULL, (void*)( &p1 ),
        NULL, NULL, NULL, NULL, NULL, NULL, NULL, (void*)( &p2 ),
    }} ;

    ::Table< int > const t =
    {
        (::Table< int >::PtrNode*)( &p3 )
    } ;

    ::Table< int > const&
    getTable()
    {
        return t ;
    }

The tables d1 and p1 are ending up in the data segment (not
write protected), where everything else is ending up in text,
where it belongs (or at least, where I want it)  Except for the
class template definition, this is machine generated code,
carefully designed to be statically initialized, and is
extracted from an example with a lot more and bigger tables,
namespaces, etc.; in every case, the first Table<int>::DataNode
table and the first Table<int>::PtrNode table end up in the data
segment.

For the moment, at least, it's not a problem, but it is curious.

--
James Kanze (GABI Software)             email:address@hidden
Conseils en informatique orientée objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


reply via email to

[Prev in Thread] Current Thread [Next in Thread]