C++ assigning integer (containing address) to pointer [duplicate]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0
















This question already has an answer here:




  • What is uintptr_t data type

    4 answers




I am new to C++, I have a function which returns address of a memory location and I want to assign that address to a pointer, just like:



unsigned int address = 0xdeadbeef;
unsigned int* memory_ptr = (unsigned int*) address;


But above code is through warning:



cast to pointer from integer of difference size [-Wint-to-pointer-cast] 


Is there anyway to do this task cleanly in C++ ?










share|improve this question













marked as duplicate by R Sahu c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 6:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

























    0
















    This question already has an answer here:




    • What is uintptr_t data type

      4 answers




    I am new to C++, I have a function which returns address of a memory location and I want to assign that address to a pointer, just like:



    unsigned int address = 0xdeadbeef;
    unsigned int* memory_ptr = (unsigned int*) address;


    But above code is through warning:



    cast to pointer from integer of difference size [-Wint-to-pointer-cast] 


    Is there anyway to do this task cleanly in C++ ?










    share|improve this question













    marked as duplicate by R Sahu c++
    Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Jan 3 at 6:36


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      0












      0








      0









      This question already has an answer here:




      • What is uintptr_t data type

        4 answers




      I am new to C++, I have a function which returns address of a memory location and I want to assign that address to a pointer, just like:



      unsigned int address = 0xdeadbeef;
      unsigned int* memory_ptr = (unsigned int*) address;


      But above code is through warning:



      cast to pointer from integer of difference size [-Wint-to-pointer-cast] 


      Is there anyway to do this task cleanly in C++ ?










      share|improve this question















      This question already has an answer here:




      • What is uintptr_t data type

        4 answers




      I am new to C++, I have a function which returns address of a memory location and I want to assign that address to a pointer, just like:



      unsigned int address = 0xdeadbeef;
      unsigned int* memory_ptr = (unsigned int*) address;


      But above code is through warning:



      cast to pointer from integer of difference size [-Wint-to-pointer-cast] 


      Is there anyway to do this task cleanly in C++ ?





      This question already has an answer here:




      • What is uintptr_t data type

        4 answers








      c++ pointers






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 3 at 6:26









      Ameer HamzaAmeer Hamza

      408




      408




      marked as duplicate by R Sahu c++
      Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Jan 3 at 6:36


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by R Sahu c++
      Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Jan 3 at 6:36


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          0














          Instead of unsigned int you can use uintptr_t.




          Integer type capable of holding a value converted from a void pointer and then be converted back to that type with a value that compares equal to the original pointer.







          share|improve this answer






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Instead of unsigned int you can use uintptr_t.




            Integer type capable of holding a value converted from a void pointer and then be converted back to that type with a value that compares equal to the original pointer.







            share|improve this answer




























              0














              Instead of unsigned int you can use uintptr_t.




              Integer type capable of holding a value converted from a void pointer and then be converted back to that type with a value that compares equal to the original pointer.







              share|improve this answer


























                0












                0








                0







                Instead of unsigned int you can use uintptr_t.




                Integer type capable of holding a value converted from a void pointer and then be converted back to that type with a value that compares equal to the original pointer.







                share|improve this answer













                Instead of unsigned int you can use uintptr_t.




                Integer type capable of holding a value converted from a void pointer and then be converted back to that type with a value that compares equal to the original pointer.








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 3 at 6:32









                YolaYola

                11.3k64672




                11.3k64672

















                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith