reinterpret_cast compile warnings

This is a discussion on reinterpret_cast compile warnings within the C++ Programming forums, part of the General Programming Boards category; To the experts, I am getting numerous reinterpert_cast warnings, error listed below, and do not understand how to clean them ...

  1. #1
    Registered User deadpoet's Avatar
    Join Date
    Jan 2004
    Posts
    50

    Question reinterpret_cast compile warnings

    To the experts,

    I am getting numerous reinterpert_cast warnings, error listed below, and do not understand how to clean them up. Can one of the experts please explain what this is about, how to avoid it, and maybe how to clean it up.


    # PROJECT dlpi
    # Building Target: getmac
    # ENV vars set: COMPFLAGS_LD_getmac=-g0 , COMPFLAGS_C_getmac=-g0 -y
    aCC -c -g0 -y -o getmac_address.o getmac_address.c
    aCC: current directory is "/build/nitro_project/dlpi"
    Warning 749: "getmac_address.c", line 103 # The cast from 'DL_primitives *' to 'dl_ok_ack_t *' is performed as a 'reinterpret_cast'. This operation is non-portable and potentially unsafe.
    if( ( ( dl_ok_ack_t * )&dl_prim)->dl_correct_primitive != DL_ATTACH_REQ
    ^^^^^^^^^^^^^^^^^

    ... OTHER WARNINGS HERE OF SIMILAR NATURE ....

    Linking getmac ...
    aCC -g0 -o getmac getmac_address.o
    aCC: current directory is "/nfs/hpux-02.reyniers.com/build/nitro_project/dlpi"
    done
    # PROJECT dlpi BUILD-TARGET Completed


    The section of my code that the compiler is complaining about is as follows:
    Code:
    union DL_primitives dl_prim;
    dl_attach_req_t attach_req;
    
    ... more code ....
    
    if ( ( ( dl_ok_ack_t * )&dl_prim)->dl_correct_primitive != DL_ATTACH_REQ ) {
        errno = EPROTO;
        return(-1);
    }
    The structure(s) being referenced are from sys/dlpi.h. I have provided code snips of these structures as defined in sys/dlpi.h.

    From dlpi.h Include:
    Code:
    /*
     * DL_OK_ACK, M_PCPROTO type
     */
    typedef struct {
            uint32_t        dl_primitive;           /* DL_OK_ACK */
            uint32_t        dl_correct_primitive;   /* primitive being acknowledged */
    } dl_ok_ack_t;
    
    union DL_primitives {
            uint32_t                        dl_primitive;
            dl_info_req_t           info_req;
            dl_info_ack_t           info_ack;
            dl_attach_req_t         attach_req;
            dl_detach_req_t         detach_req;
            dl_bind_req_t           bind_req;
            dl_bind_ack_t           bind_ack;
            dl_unbind_req_t         unbind_req;
            dl_subs_bind_req_t      subs_bind_req;
            dl_subs_bind_ack_t      subs_bind_ack;
            dl_subs_unbind_req_t    subs_unbind_req;
            dl_ok_ack_t             ok_ack;
            dl_error_ack_t          error_ack;
            dl_connect_req_t        connect_req;
            dl_connect_ind_t        connect_ind;
            dl_connect_res_t        connect_res;
            dl_connect_con_t        connect_con;
            dl_token_req_t          token_req;
            dl_token_ack_t          token_ack;
            dl_disconnect_req_t     disconnect_req;
            dl_disconnect_ind_t     disconnect_ind;
            dl_reset_req_t          reset_req;
            dl_reset_ind_t          reset_ind;
            dl_reset_res_t          reset_res;
            dl_reset_con_t          reset_con;
            dl_unitdata_req_t       unitdata_req;
            dl_unitdata_ind_t       unitdata_ind;
            dl_uderror_ind_t        uderror_ind;
            dl_udqos_req_t          udqos_req;
            dl_enabmulti_req_t      enabmulti_req;
            dl_disabmulti_req_t     disabmulti_req;
            dl_promiscon_req_t      promiscon_req;
            dl_promiscoff_req_t     promiscoff_req;
            dl_phys_addr_req_t      physaddr_req;
            dl_phys_addr_ack_t      physaddr_ack;
            dl_set_phys_addr_req_t  set_physaddr_req;
            dl_get_statistics_req_t get_statistics_req;
            dl_get_statistics_ack_t get_statistics_ack;
            dl_test_req_t           test_req;
            dl_test_ind_t           test_ind;
            dl_test_res_t           test_res;
            dl_test_con_t           test_con;
            dl_xid_req_t            xid_req;
            dl_xid_ind_t            xid_ind;
            dl_xid_res_t            xid_res;
            dl_xid_con_t            xid_con;
            dl_data_ack_req_t       data_ack_req;
            dl_data_ack_ind_t       data_ack_ind;
            dl_data_ack_status_ind_t        data_ack_status_ind;
            dl_reply_req_t          reply_req;
            dl_reply_ind_t          reply_ind;
            dl_reply_status_ind_t   reply_status_ind;
            dl_reply_update_req_t   reply_update_req;
            dl_reply_update_status_ind_t    reply_update_status_ind;
    };
    
    #define DL_OK_ACK_SIZE          sizeof(dl_ok_ack_t)
    Thanks In Advance for Any and All Assistance,

    DeadPoet

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>( ( dl_ok_ack_t * )&dl_prim)
    Why are you casting the pointer to something that it isn't?

    &dl_prim is of type DL_primitives*, casting and dereferencing it incorrectly will cause you problems.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User deadpoet's Avatar
    Join Date
    Jan 2004
    Posts
    50

    Wink

    This is inherited code that I have to port. I am trying to understand what the thought process is that they were using. So, suggestions and pointer on what I sould do to fix the issue at hand would be great.

    Thanks In Advance,

    DeadPoet

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 09:05 PM
  2. open scene graph compile issues
    By ichijoji in forum Game Programming
    Replies: 1
    Last Post: 08-04-2005, 01:31 PM
  3. compile program?
    By Goosie in forum C++ Programming
    Replies: 9
    Last Post: 06-22-2005, 03:26 PM
  4. dvv-cpp not able to compile?
    By Rune Hunter in forum C++ Programming
    Replies: 12
    Last Post: 10-23-2004, 07:36 PM
  5. Compile Problems
    By Eber Kain in forum C++ Programming
    Replies: 1
    Last Post: 08-26-2001, 02:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21